Skip to content

Instantly share code, notes, and snippets.

@CHH
CHH / README.md
Last active December 15, 2015 02:39
Configuring a Heroku Buildpack via the composer.json?

Unofficial Heroku Buildpack for PHP

This Heroku Buildpack adds more advanced support for PHP.

  • Runs apps written for both PHP 5.4 and 5.3
  • Supports Composer dependencies and caching of the vendor/ directory for fast deploys
  • Simple configuration via the project's composer.json
  • Stable and fast setup using NGINX, PHP-FPM and Zend Optimizer Plus
@CHH
CHH / 00_rfc_decorators.md
Last active March 20, 2023 13:48
PHP Decorators RFC

PHP Decorators (alternative proposal to Annotations)

Inspiration: Python Decorators

Todo

  • Further refine how class decorators should work. Should they work on the instance level? Or should they just receive the class name, and can only be used for providing metadata? Instance level is probably the only one that makes sense in PHP. Problem is though, that then the decorator is not called when used in the declaration.
@CHH
CHH / struct.php
Last active December 10, 2015 20:59
A simple struct class for PHP.
<?php
abstract class Struct implements \ArrayAccess
{
function __construct($properties = array())
{
$this->init();
foreach ($properties as $property => $value) {
$this->$property = $value;
@CHH
CHH / composer.json
Created December 19, 2012 16:24
React Promise + libuv fun!
{
"require": {
"react/promise": "*@dev"
}
}
@CHH
CHH / silex_cli.php
Created December 7, 2012 09:02
Silex for the CLI
<?php
$app = new Application;
$app->match('greet [--yell] <name>', function($name, $options) {
$message = "Hello $name!";
if (isset($options['yell'])) {
$message = strtoupper($message);
}
@CHH
CHH / gist:4086320
Created November 16, 2012 10:40
XDebug compile error on 5.5.0alpha1
/var/tmp/php-build/source/xdebug-master/xdebug.c:567:30: warning: incompatible pointer types assigning to 'void (*)(zend_execute_data *, int)' from 'void (*)(zend_execute_data *, struct _zend_fcall_info *, int)' [-Wincompatible-pointer-types]
xdebug_old_execute_internal = zend_execute_internal;
^ ~~~~~~~~~~~~~~~~~~~~~
/var/tmp/php-build/source/xdebug-master/xdebug.c:568:24: warning: incompatible pointer types assigning to 'void (*)(zend_execute_data *, struct _zend_fcall_info *, int)' from 'void (zend_execute_data *, int)' [-Wincompatible-pointer-types]
zend_execute_internal = xdebug_execute_internal;
^ ~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/php-build/source/xdebug-master/xdebug.c:704:24: warning: incompatible pointer types assigning to 'void (*)(zend_execute_data *, struct _zend_fcall_info *, int)' from 'void (*)(zend_execute_data *, int)' [-Wincompatible-pointer-types]
zend_execute_internal = xdebug_old_execute_internal;
@CHH
CHH / iterator_map.php
Created November 7, 2012 14:26
iterator_map function using Generators
<?php
function iterator_map(callable $callback)
{
$iterators = array_slice(func_get_args(), 1);
$multi = new MultipleIterator;
foreach ($iterators as $it) {
$multi->attachIterator($it);
}
@CHH
CHH / server.php
Created May 30, 2012 06:13
Einhorn PHP Example
<?php
declare(ticks = 1);
# Einhorn sends a "USR2" signal to our server process
# in case the server shuts down.
pcntl_signal(SIGUSR2, function() {
fwrite(STDERR, "Worker shutting down...\n");
exit(0);
});
@CHH
CHH / cli.php
Created May 18, 2012 10:13
Run something only when the file is invoked on the command line.
<?php
# Some regular library code, which can be used by including
# the file.
class Foo
{
# Do not use a global function, because you get an error
# if you try to redefine it.
static function __main()
{
@CHH
CHH / compile_flags.txt
Created March 7, 2012 12:56 — forked from xenji/compile_flags.txt
Compile flags for xcache and memcache for php5.4.0
CFLAGS="-D_REENTRANT -D_THREAD_SAFE -O3 -pipe -pthread" CXXFLAGS="-D_REENTRANT -D_THREAD_SAFE -O3 -pipe -pthread" ./configure