Tagphp

WP-CLI becomes part of make.wordpress.org

WP-CLI reached 1.x stable release. WordPress decided to make it as part of make.wordpress.org tools.

Great news from the WordPress community and those who spends most of their time in the console. No more weird sftpd/vsftpd installations.

It might come handy with composer bundle as we do it in Qobo for WordPress project templates.

PSR-7: storage-less sessions

Some measurements on Arrays vs ArrayObjects found among gist users. Just going to bring it here, in case gist dissappears.

# php -v
PHP 5.3.6 (cli) (built: Mar 17 2011 20:58:15)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

# echo '<?php $s = array(); for($x=0;$x<1000;$x++){ $s[] = array("name"=>"Adam","age"=>35); }; echo memory_get_peak_usage(); ' | php
655040

# echo '<?php $s = array(); for($x=0;$x<1000;$x++){ $o = new ArrayObject; $o->name = "Adam";  $o->age = 35;  $s[] = $o;} echo memory_get_peak_usage(); ' | php
887984

# time echo '<?php $s = array(); for($x=0;$x<100000;$x++){ $o = new ArrayObject; $o->name = "Adam";  $o->age = 35;  $s[] = $o;} echo memory_get_peak_usage(); ' | php
61010784
real    0m1.448s
user    0m1.208s
sys     0m0.231s

# time echo '<?php $s = array(); for($x=0;$x<100000;$x++){ $s[] = array("name"=>"Adam","age"=>35); }; echo memory_get_peak_usage(); ' | php
33647944
real    0m0.525s
user    0m0.429s
sys     0m0.092s

We can conclude the following at least in PHP 5.6:

  • Winner for Speed: Arrays are faster than objects (with undefined or defined properties)
  • Winner for Memory: Objects with defined properties use less memory, 50%+ less than objects with undefined properties, only slightly less than Arrays

Ordered Fastest to Slowest in Speed for 100,000 items:

  • 0.107s – Arrays
  • 0.163s – Objects with undefined properties
  • 1.190s – Objects with defined properties

Ordered Least to Most Memory Usage for 1,000 items:

  • ~583kb – Objects with defined properties
  • ~807kb – Arrays
  • ~1.1mb – Objects with undefined properties

Chronos: CakePHP replacement for carbon

Chronos is a drop-in library replacement for nesbot/carbon.

It provides immutable date/datetime objects. Immutable objects help us to ensure, that DateTime objects aren’t accidentally modified.

<?php
require 'vendor/autoload.php';
use Cake\Chronos\Chronos;
printf("Now: %s", Chronos::now());
?>

CakePHP 3 adopts PSR-2

Recently read this article from James Watts:

By adopting PSR-2 we can remove or reduce the code we maintain related to enforcing coding standards.

As there are common tools, used by the rest of the community, to validate and revise CS issues, without requiring exceptions.

james watts

Looks like it’s the time to re-write our internal modules with PSR-2 standards in mind. If we want to share them with open-source community, of course