Skip to content

Instantly share code, notes, and snippets.

View igorgolovanov's full-sized avatar

Igor Golovanov igorgolovanov

View GitHub Profile
@igorgolovanov
igorgolovanov / oo.php
Created February 17, 2012 16:31 — forked from dhotson/oo.php
PHP Object Oriented Programming Reinvented (for PHP 5.4)
<?php
// Define the 'class' class
$class = (new Obj)
->fn('new', function() {
$newClass = (new Obj($this->methods))
->fn('new', function() {
$obj = new Obj($this->imethods);
call_user_func_array(array($obj, 'init'), func_get_args());
return $obj;

Installation

This procedure is tested on Mac OS X 10.8 with Developpers tools installed (xCode).

PHP 5.4 installed with Homebrew.

Update: I wrote a blog post about this.

Preparation

Download the following files from Oracle website (yes, you need to create an account and accept terms):

Easy pthreads Pools

The final solution !!

Since the first version of pthreads, PHP has had the ability to initialize Worker threads for users. Onto those Worker threads are stacked objects of class Stackable for execution concurrently.

The objects stacked onto workers do not have their reference counts changed, pthreads forces the user to maintain the reference counts in userland, for the extremely good reason that this enables the programmer to keep control of memory usage; and so, execute indefinitely.

This is the cause of much heartache for newcomers to pthreads; if you do not maintain references properly you will, definitely, experience segmentation faults.

Multi-Threading in PHP with pthreads

A Brief Introduction to Multi-Threading in PHP

  • Foreword
  • Execution
  • Sharing
  • Synchronization
  • Pitfalls
#!/bin/bash
# This should be a path that the user executing the script can read and write
PHP_PATH=/opt/php-ts
# This should be a sensible version of PHP
PHP_VERSION=5.4.11
# This should be a sensible mirror for your location
PHP_MIRROR=uk1.php.net
# This should be a released version of pthreads
PHP_PTHREADS=0.0.42
# This should be set to 0 if you do not want to remove build directories
@igorgolovanov
igorgolovanov / README.md
Last active August 29, 2015 14:12 — forked from denji/readme-php7.md
Quick install PHP 7.0 (phpng) - OS X

Quick install PHP 7.0 (phpng):

1. Install depends PHP 7.0 (phpng)
$ brew install autoconf automake bison27 gd freetype t1lib mariadb gettext zlib mcrypt
Add support for Bison 3.x

curl -L https://github.com/php/php-src/pull/685.diff | patch -p1

Quick install PHP 7.0 (phpng):

1. Install depends PHP 7.0 (phpng)
$ brew install autoconf automake bison27 gd freetype t1lib mariadb gettext zlib mcrypt
Add support for Bison 3.x

curl -L https://github.com/php/php-src/pull/685.diff | patch -p1

Port Forwarding in Mavericks


Since Mavericks stopped using the deprecated ipfw (as of Mountain Lion), we'll be using pf to allow port forwarding.

####1. anchor file Create an anchor file under /etc/pf.anchors/<anchor file> with your redirection rule like:

@igorgolovanov
igorgolovanov / introrx.md
Created January 2, 2017 15:04 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing