只要任何PHP腳本的執行開始,是否可以觸發一個函數的調用?是否可以在PHP腳本執行開始後自動調用函數?
例如
<?php
Include 'a.php';
Include 'b.php';
?>
所以我想實現儘快a.php只會包括呼叫應觸發的功能。
應該有像register_shut_down這樣的東西,但是這個功能在腳本關閉時間執行。
只要任何PHP腳本的執行開始,是否可以觸發一個函數的調用?是否可以在PHP腳本執行開始後自動調用函數?
例如
<?php
Include 'a.php';
Include 'b.php';
?>
所以我想實現儘快a.php只會包括呼叫應觸發的功能。
應該有像register_shut_down這樣的東西,但是這個功能在腳本關閉時間執行。
是的,這是可能的,使用行.htaccess文件:
php_value auto_prepend_file "prepended.php"
或者你的php.ini裏當然,但如果您在同一臺服務器上託管多個網站,我不會推薦它。
它的工作。謝謝。 – 2011-06-03 11:20:38
是的,你可以做到這一點:
http://php.net/manual/en/ini.core.php#ini.auto-prepend-file
Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the require() function, so include_path is used.
The special value none disables auto-prepending.
它很有效。謝謝。 – 2011-06-03 11:21:15
和順便說一句,我是30秒更快xD – dynamic 2011-06-03 11:51:19
您的意思是「何時啓動腳本」或「何時包含/需要腳本」? – Yeroon 2011-06-03 11:16:42
是Yeroon,只要腳本啓動 – 2011-06-03 11:18:08
在'__construct()中調用該方法' – diEcho 2011-06-03 11:21:12