register_shutdown_function vs __destruct
1366 ワード
phpではなぜ_destruct関数の後にregister_shutdown_义齿
コードはすべてを説明します.
コードはすべてを説明します.
<?php
class T1
{
function __construct()
{
register_shutdown_function(array(&$this, 'shutdown_func'));
}
function shutdown_func() {
$fp = fopen("/tmp/t1.txt", "w+");
fputs($fp, "
");
fclose($fp);
}
};
$obj = new T1();
while (true) {
// do nothing
}
:
Fatal error: Maximum execution time of 30 seconds exceeded in /home/hanyh/workspace/website/t1.php on line 19
:
hanyh@hanyh:~/workspace/git/django-pagination$ more /tmp/t1.txt
<?php
class T2
{
function __destruct()
{
$fp = fopen("/tmp/t2.txt", "w+");
fputs($fp, "
");
fclose($fp);
}
};
$obj = new T2();
while (true) {
// do nothing
}
:
Fatal error: Maximum execution time of 30 seconds exceeded in /home/hanyh/workspace/website/t2.php on line 13
:
hanyh@hanyh:~/workspace/git/django-pagination$ more /tmp/t2.txt
/tmp/t2.txt:
, register_shutdown_function , 。 , register_shutdown_function。