我想在脚本结束时记录一些信息,所以我想使用register_shutdown_function
,有人可以解释一下为什么会这样做:
<?php
//register_shutdown_function('on_exit');
on_exit(); //FUNCTION on_exit CALLED NORMALLY
function on_exit(){
$path = './myfolder/myfile';
$fo = fopen($path,'w+');
fwrite($fo,"Test");
fclose($fo);
}
?>
而这不是:
<?php
register_shutdown_function('on_exit'); //FUNCTION on_exit CALLED FROM SHUTDOWN FUNCTION
//on_exit();
function on_exit(){
$path = './myfolder/myfile';
$fo = fopen($path,'w+');
fwrite($fo,"Test");
fclose($fo);
}
?>
返回
Warning: fopen(./myfolder/myfile): failed to open stream: No such file or directory in C:\xampp\htdocs\test.php on line 6
Warning: fwrite() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 7
Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 8