Reputation: 111
I have one simple PHP file which I am running from command line like
php my-file.php
and its working fine without any issue. I want run another file when some event happen like below
<?php
echo " hello this is sample";
exit();
// I want run another file here after exit command called
next-file.php
echo "next-file is successfully running";
?>
Let me know if someone can give idea how can I achieve this? Thanks
Upvotes: 3
Views: 6223
Reputation: 4389
Use include_once 'next-file.php';
to import and run the code.
Then related to PHP Doc, here is the definition of exit()
:
Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called.
So add this code line into the shutdown function as below:
function shutdown()
{
include_once 'next-file.php';
echo "next-file is successfully running", PHP_EOL;
}
register_shutdown_function('shutdown');
Be sure to record this function before the exit()
.
Upvotes: 3
Reputation: 1
you can execute a shell command from php using exec()
http://php.net/manual/en/function.exec.php
Upvotes: 0