IS可以在PHP脚本';s的执行开始


IS to possible to auto call a function as soon as PHP script's execution is started?

是否可以在任何PHP脚本开始执行后立即触发对函数的调用?

例如

<?php
Include 'a.php';
Include 'b.php';
?>

因此,我想要实现的是,一旦包含了.php,就应该触发对函数的调用。

应该有类似register_shut_down的东西,但此函数在脚本关闭时间执行

是的,您可以使用:

http://php.net/manual/en/ini.core.php#ini.auto-准备文件

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.

是的,这是可能的,使用.htaccess文件中的一行:

php_value auto_prepend_file "prepended.php"

当然,也可以在php.ini中,但如果您在同一台服务器上托管多个网站,我不建议使用它。