I would like to kill a php script, say script A.php
, (while it is running) from inside another php script say script B.php
. When script A.php
starts I would like to save some kind of ID
into the database. When script B.php
starts running I want to get that ID
from the database and use that to exit
or kill
script A.php
inmediately.
我想杀死一个PHP脚本,说脚本A.php,(当它运行时)来自另一个PHP脚本说脚本B.php。当脚本A.php启动时,我想将某种ID保存到数据库中。当脚本B.php开始运行时,我想从数据库中获取该ID,并使用它来立即退出或终止脚本A.php。
Is this possible, and how can I do that?
这可能,我该怎么做?
UPDATE 1
There can be multiple instances of A.php in which case I only want to kill a single instance of A.php. I can get the Process ID at the beginning of each script and save it either in a database or SESSION variable B.php knows which A.php script to kill.
可能有多个A.php实例,在这种情况下我只想杀死A.php的单个实例。我可以在每个脚本的开头获取进程ID并将其保存在数据库或SESSION变量中.Bph知道要杀死哪个A.php脚本。
This application is used within the backend program of a website. The reason for killing the scripts A.php is because some users click on many buttons which trigger A.php to run. As A.php takes around 5 seconds to run and only the latest version of A.php is required I would like to kill other A.php scripts that are still running to save server resources as I am not interesting in the outcome anymore.
此应用程序在网站的后端程序中使用。杀死脚本A.php的原因是因为一些用户点击了许多触发A.php运行的按钮。由于A.php需要大约5秒才能运行,并且只需要最新版本的A.php,我想杀死其他仍在运行以保存服务器资源的A.php脚本,因为我对结果不再感兴趣。
1 个解决方案
#1
1
To kill scriptA.php from scriptB.php you must be able to execude system commands, and you should not running this within a webserver.
要从scriptB.php中终止scriptA.php,您必须能够执行系统命令,并且不应在Web服务器中运行它。
You could store the pid
of scriptA.php
within the database. To get it use getmypid(). In scriptB.php
you could use the system()
function to kill the other process:
您可以将scriptA.php的pid存储在数据库中。要使用getmypid()。在scriptB.php中,您可以使用system()函数来终止其他进程:
system("kill $pidOfScriptA");
#1
1
To kill scriptA.php from scriptB.php you must be able to execude system commands, and you should not running this within a webserver.
要从scriptB.php中终止scriptA.php,您必须能够执行系统命令,并且不应在Web服务器中运行它。
You could store the pid
of scriptA.php
within the database. To get it use getmypid(). In scriptB.php
you could use the system()
function to kill the other process:
您可以将scriptA.php的pid存储在数据库中。要使用getmypid()。在scriptB.php中,您可以使用system()函数来终止其他进程:
system("kill $pidOfScriptA");