我有一个简单的PHP文件,该文件从命令行运行,例如
php my-file.php
及其正常工作没有任何问题。 我想在发生以下类似事件时运行另一个文件
<?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";
?>
让我知道是否有人可以提出想法,我该如何实现? 谢谢
答案 0 :(得分:2)
使用"cd ./code"
导入并运行代码。
然后与PHP Doc有关,这是include_once 'next-file.php';
的定义:
终止脚本的执行。即使调用exit,关机功能和对象析构函数也将始终执行。
因此,将此代码行添加到关闭功能中,如下所示:
exit()
请务必在function shutdown()
{
include_once 'next-file.php';
echo "next-file is successfully running", PHP_EOL;
}
register_shutdown_function('shutdown');
之前记录此功能。
答案 1 :(得分:0)
您可以使用exec()从php执行shell命令