Skip to content

Instantly share code, notes, and snippets.

@krakjoe
krakjoe / pthreads.md
Last active September 24, 2024 14:50
pthreads.md

Multi-Threading in PHP with pthreads

A Brief Introduction to Multi-Threading in PHP

  • Foreword
  • Execution
  • Sharing
  • Synchronization
  • Pitfalls
@nikic
nikic / bench.php
Last active December 16, 2024 20:30
Benchmark of call_user_func_array vs switch optimization vs argument unpacking syntax
<?php error_reporting(E_ALL);
function test() {}
$nIter = 1000000;
$argNums = [0, 1, 2, 3, 4, 5, 100];
$func = 'test';
foreach ($argNums as $argNum) {
@mnapoli
mnapoli / DI containers summary.md
Last active May 7, 2018 07:58
DI containers usage comparison
@nettles-jarrod
nettles-jarrod / blog - Explaining My Choices Further.md
Last active April 25, 2023 19:31
In which I do a little digging about the choices I've made with PHP. This is a long read, but it isn't something that can be explained in one or two paragraphs.

In the comments from my last post and on Twitter I noticed a lot of people who had something to say about PHP. The comments were varied but they usally sounded something like this (sorry @ipetepete, I picked yours because it was the shortest).

...the little bits of soul from all of us who've had to work on, and or maintain large PHP applications. – ipetepete

In Pete's defense, he did go on to say that rest of the stack I was using was a "smorgasbord of awesome". Thanks, Pete. I agree!

I would, however, like to take a little time to correct a misperception in the developer community about PHP. I recently got into this same... discussion... with Jeff Atwood, and I seem to be running into it more and more. So here goes. Please bear with me as I cover a little history further on.

Pete, and everybody else, _you're exactly rig

@nikic
nikic / php-5.5-features.md
Last active August 31, 2020 10:39
List of new features in PHP 5.5
@nicmart
nicmart / mediawiki-globals-1.20.php
Created March 8, 2013 15:20
Mediawiki 1.20 globals. Wrapping mediawiki code into a symfony application forced me to explicitly declare all global variables (more than 800!). This is the file I include for that declarations.
<?php
/*
* This file lists all global variables found in Medawiki 1.20
*
* (c) 2013 Nicolò Martini <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@nikic
nikic / objects_arrays.md
Last active January 31, 2025 21:17
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@lavoiesl
lavoiesl / benchmark.php
Created September 4, 2012 00:21
Benchmark of different function calls in PHP
<?php
// Commons
$callable = function() {};
function empty_function() {};
class A {
public static function empty_function() {}
public function empty_method () {}
}
@ziadoz
ziadoz / awesome-php.md
Last active February 3, 2025 20:55
Awesome PHP — A curated list of amazingly awesome PHP libraries, resources and shiny things.
@retronym
retronym / forall.scala
Created November 26, 2011 18:21
universal quantification
scala> trait Forall[F[_]]{ def apply[A]: F[A] }
defined trait Forall
scala> type ListFun[A] = List[A] => List[A]
defined type alias ListFun
scala> object Reverse extends Forall[ListFun] { def apply[A] = _.reverse}
defined module Reverse
scala> Reverse[String](List("1", "2"))