Jatin Dhoot
Jatin Dhoot

Reputation: 4364

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

Is it possible to trigger a call to a function as soon as any PHP script's execution is started ?

e.g.

<?php

Include 'a.php';
Include 'b.php';

?>

So what I want to achieve is as soon as a.php is included a call should be triggered to a function.

There should be something like register_shut_down but this function is executed at script shut down time.

Upvotes: 1

Views: 803

Answers (2)

Yeroon
Yeroon

Reputation: 3243

Yes this is possible, using a line in your .htaccess file:

php_value auto_prepend_file "prepended.php"

Or inside you php.ini ofcourse, but I'd not recommend it if you host multiple websites on the same server.

Upvotes: 0

dynamic
dynamic

Reputation: 48091

Yes you can do that with:

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.

Upvotes: 3

Related Questions