Skip to content

Instantly share code, notes, and snippets.

@krakjoe
krakjoe / pthreads-helper
Last active August 20, 2019 21:05
pthreads-helper to download/install php+pthreads isolated
#!/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=7.0.0
# This should be a sensible mirror for your location
PHP_MIRROR=uk1.php.net
# This should be a released version of pthreads
PHP_PTHREADS=3.1.5
# This should be set to 0 if you do not want to remove build directories
@krakjoe
krakjoe / workers.php
Created February 26, 2014 17:12
using workers
<?php
define("SECOND", 1000000);
class Task extends Stackable {
public function run() {
/* some random data */
$this->data = md5(
mt_rand() * microtime());
}
}
@krakjoe
krakjoe / fib.php
Last active June 11, 2019 09:33
SMP Fibonacci with pthreads
<?php
/**
* SMP Fibonacci
*
* Fibonacci sequencing is often used to show the virtues of such things as HHVM
*
* People think of it as a task that cannot be multi-threaded, this is flat out wrong.
*
* It can be multi-threaded, even in PHP, to great effect.
*
@krakjoe
krakjoe / opcache.diff
Created April 14, 2017 10:21
7.1.0 ... 7.1.4 ext/opcache
diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c
index 77b02cc99f..38c2ecb124 100644
--- a/ext/opcache/Optimizer/block_pass.c
+++ b/ext/opcache/Optimizer/block_pass.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| Zend OPcache |
+----------------------------------------------------------------------+
- | Copyright (c) 1998-2016 The PHP Group |
+ | Copyright (c) 1998-2017 The PHP Group |
<?php
use UI\App;
use UI\Window;
use UI\Point;
use UI\Size;
use UI\Area;
use UI\Controls\Box;
use UI\Draw\Pen;
use UI\Draw\Brush;
use UI\Draw\Path;
@krakjoe
krakjoe / mm.patch
Created January 22, 2017 18:58
gd mm
diff --git a/src/gdhelpers.c b/src/gdhelpers.c
index 20fff5c..a64278b 100644
--- a/src/gdhelpers.c
+++ b/src/gdhelpers.c
@@ -14,6 +14,33 @@
#define SEP_TEST (separators[*((unsigned char *) s)])
+static inline void* gd_malloc_wrapper(size_t size)
+{
@krakjoe
krakjoe / demo.php
Last active December 2, 2016 05:28
PCNTL+pools+workers+pthreads
<?php
declare(ticks=1);
/*
This is your container for workers, it is only used in the process itself, so there is no need to descend from pthreads
*/
class Pool {
public $max;
public $config;
public $stop;
@krakjoe
krakjoe / variance-correct-probably.patch
Last active November 14, 2016 10:21
variance corrections
diff --git a/Zend/tests/object_types/variance_in_param.phpt b/Zend/tests/object_types/variance_in_param.phpt
index bcc528e..cf28dd8 100644
--- a/Zend/tests/object_types/variance_in_param.phpt
+++ b/Zend/tests/object_types/variance_in_param.phpt
@@ -15,6 +15,7 @@ class Bar extends Foo {
var_dump(new Bar);
?>
--EXPECTF--
+Warning: Declaration of Bar::qux(Qux $qux) should be compatible with Foo::qux(object $object) in %s on line 10
object(Bar)#%d (0) {
@krakjoe
krakjoe / starfield.d
Created November 8, 2016 11:06
Starfield in D, uses krakjoe/dui (or any other 1:1 module)
import std.random;
import andlabs.libui;
struct Star {
double X;
double Y;
double V;
bool F;
double G;
krakjoe@fiji:/usr/src/php-src$ sapi/cli/php -n prop.php
empty_loop 0.060
write_prop1() 0.085 0.025
write_prop2() 0.070 0.010
write_prop3() 0.058 -0.002
------------------------
Total 0.274
krakjoe@fiji:/usr/src/php-src$ sapi/cli/php -n prop.php
empty_loop 0.059
write_prop1() 0.086 0.027