PHPackages                             radiosilence/ham - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. radiosilence/ham

ActiveLibrary

radiosilence/ham
================

PHP Microframework for use with whatever you like.

38447311PHP

Since Jul 3Pushed 10y ago15 watchersCompare

[ Source](https://github.com/radiosilence/Ham)[ Packagist](https://packagist.org/packages/radiosilence/ham)[ RSS](/packages/radiosilence-ham/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (1)Used By (1)

Ham
===

[](#ham)

*Now includes tests!*

PHP Microframework for use with whatever you like. Basically just a fast router with nice syntax, and a cache singleton. Will add more things as I go, like perhaps an extension system, autoloader and some other stuff to make developing in PHP less irritating than it currently is.

Routes are converted to regex and cached so this process does not need to happen every request. Furthermore, the resolved route for a given URI is also cached so on most requests thare is no regex matching involved.

There is also now the ability to mount apps on routes within apps, so one could make an administrator app, then mount it on the main app at /admin.

PHP presents an interesting challenge because due to it's architecture, everything has to be re-done each request, which is why I'm leveraging caching with tiny TTLs to share the results of operations like route resolution between requests.

Note: PHP already has many of the features that many microframeworks have, such as session handling, cookies, and templating. An aim of this project is to encourage the use of native functionality where possible or where it is good, but make some parts nicer or extend upon them to bring it up to scratch with the way I like things.

Note: For maximum speed gains, use the XCache extension because that supports caching of closures, unlike APC.

Goals
-----

[](#goals)

- Make pretty much anything I/O related cached with XCache/APC (whichever is installed) in order to prevent excessive disk usage or path searching on lots of requests.
- Provide a succinct syntax that means less magic and less code to read through and learn, without compromising speed or code length, by using native PHP methods and features.
- Promote a simple, flat way of building applications that don't need massive levels of abstraction.
- Encourage use of excellent third-party libraries such as Doctrine to prevent developers writing convoluted, unmaintainable code that people like me have to pick up and spend hours poring over just to get an idea of what on earth is going on.
- Define and document development patterns that allow for new developers to get up to speed quickly and write new code that isn't hacky.

Inspired entirely by Flask.

Requirements
------------

[](#requirements)

- PHP 5.3
- XCache (preferred) or APC (still optional)
- Requests pointed at file that you put the app in (eg. index.php).

Hello World
-----------

[](#hello-world)

```
require '../ham/ham.php';

$app = new Ham('example');

$app->route('/', function($app) {
    return 'Hello, world!';
});

$app->run();
```

More Interesting Example
------------------------

[](#more-interesting-example)

```
require '../ham/ham.php';

$app = new Ham('example');
$app->config_from_file('settings.php');

$app->route('/pork', function($app) {
    return "Delicious pork.";
});

$hello = function($app, $name='world') {
    return $app->render('hello.html', array(
        'name' => $name
    ));
};
$app->route('/hello/', $hello);
$app->route('/', $hello);

$app->run();
```

Multiple apps mounted on routes!
--------------------------------

[](#multiple-apps-mounted-on-routes)

```
require '../ham/ham.php';

$beans = new Ham('beans');

$beans->route('/', function($app) {
    return "Beans home.";
});

$beans->route('/baked', function($app) {
    return "Yum!";
});

$app = new Ham('example');
$app->route('/', function($app) {
    return "App home.";
});
$app->route('/beans', $beans);
$app->run();
```

Custom Error Handeling
----------------------

[](#custom-error-handeling)

```
require 'ham/ham.php';

$beans = new Ham('beans');

$beans->route('/', function($app) {
    return "Beans home.";
});

$app->onError(function(){
    return "Burnt Bacon.";
}, "Error message can go here.");

$app->run();
```

Output:

#### /beans/

[](#beans)

Beans home.

#### /beans/baked

[](#beansbaked)

Yum!

#### /

[](#)

App home.

#### /definitely\_not\_the\_page\_you\_were\_looking\_for

[](#definitely_not_the_page_you_were_looking_for)

Burnt Bacon.

Have a gander at the example application for more details.

To-Dos
------

[](#to-dos)

- Nice logging class and logging support with error levels, e-mailing, etc.
- Sub-application mounting (ala Flask "Blueprints").
- Sanitisation solution.
- CSRF tokens
- Extension API

Extension Ideas
---------------

[](#extension-ideas)

- Form generation (3rd-party? Phorms)
- ORM integration (most likely Doctrine)
- Auth module (using scrypt or something)
- Admin extension

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community29

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4232bff51ec1380e748a6829d6f98b88a15f16cc70af454da69d50c469d8c889?d=identicon)[jeremykendall](/maintainers/jeremykendall)

![](https://www.gravatar.com/avatar/b10d4899ab05b339b4e400c8ef068a57439169002b0754007bff938c511b2d72?d=identicon)[radiosilence](/maintainers/radiosilence)

---

Top Contributors

[![jstacoder](https://avatars.githubusercontent.com/u/4082254?v=4)](https://github.com/jstacoder "jstacoder (11 commits)")[![jeremykendall](https://avatars.githubusercontent.com/u/288613?v=4)](https://github.com/jeremykendall "jeremykendall (5 commits)")[![robmiller](https://avatars.githubusercontent.com/u/873348?v=4)](https://github.com/robmiller "robmiller (5 commits)")[![gigablah](https://avatars.githubusercontent.com/u/471275?v=4)](https://github.com/gigablah "gigablah (3 commits)")[![radiosilence](https://avatars.githubusercontent.com/u/65021?v=4)](https://github.com/radiosilence "radiosilence (2 commits)")[![champloo11](https://avatars.githubusercontent.com/u/392717?v=4)](https://github.com/champloo11 "champloo11 (2 commits)")[![miramir](https://avatars.githubusercontent.com/u/686364?v=4)](https://github.com/miramir "miramir (2 commits)")[![wogsland](https://avatars.githubusercontent.com/u/3073735?v=4)](https://github.com/wogsland "wogsland (1 commits)")[![chrislaskey](https://avatars.githubusercontent.com/u/461172?v=4)](https://github.com/chrislaskey "chrislaskey (1 commits)")[![thisisbrians](https://avatars.githubusercontent.com/u/1228122?v=4)](https://github.com/thisisbrians "thisisbrians (1 commits)")[![bronzehedwick](https://avatars.githubusercontent.com/u/637174?v=4)](https://github.com/bronzehedwick "bronzehedwick (1 commits)")

### Embed Badge

![Health badge](/badges/radiosilence-ham/health.svg)

```
[![Health](https://phpackages.com/badges/radiosilence-ham/health.svg)](https://phpackages.com/packages/radiosilence-ham)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
