Skip to content

Instantly share code, notes, and snippets.

@ichikaway
Created July 17, 2012 14:59
Show Gist options
  • Save ichikaway/3129900 to your computer and use it in GitHub Desktop.
Save ichikaway/3129900 to your computer and use it in GitHub Desktop.
check copy on write of PHP
<?php
$GLOBALS['memstart'] = memory_get_usage();
function mem() {
$m2 = memory_get_usage();
echo $m2 - $GLOBALS['memstart'] ."\n";
}
class Foo {
public function bar($x = null){
echo "---------start Foo->bar() ----------\n";
$c = $x;
mem();
$c[1] = 21;
mem();
}
}
function func($x=null) {
echo "---------start foo func----------\n";
$c = $x;
mem();
$c[1] = 21;
mem();
}
$a = range(1,100);
$b = $a;
#$b[1] = 111;
func($a);
$foo = new Foo();
$foo->bar($a);
echo "------- end this script -----------\n";
mem();
echo "\n\n";
/*
RESULT
---------start foo func----------
15176
25200
---------start Foo->bar() ----------
15528
25552
------- end this script -----------
15528
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment