如何停止 PHP 脚本?阻止发送电子邮件?
我有一个 php 应用程序(使用 LAMP 堆栈)发送数千个应用程序。我很想强制停止发送电子邮件。显然我无法通过关闭浏览器来停止 senidng。
我应该杀死进程,还是有其他方法可以这样做?我应该杀死什么进程?可能不止一个..?
PS:当然,该应用程序设计得很糟糕..但这不是问题。
I have a php application (using a LAMP stack) that sends thousands of application. I would love to stop by force emails to be sent. I can't stop the senidng by closing the browser obviously.
Should I kill processes, or is there any other way to do so ? What process should I kill ? There may be more than one..?
PS: Of course, the application is badly designed.. but here is not the question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果它是您自己的(自己编写的)应用程序,也许您应该添加一些允许您暂停或停止执行的功能。
一个例子是在每 X 次迭代中,脚本都会检查资源中的命令。如果资源队列中有命令,它将按顺序执行它们,删除它们并继续(如果适用)。
例如,平面文件或数据库,您可以添加
STOP-SUSPEND_EXECUTION
命令。当您的脚本读取该行或行时,它会暂停正常执行,但会继续定期检查资源。此后,如果读取RESUME
命令,则会从中断处恢复执行,因为它尚未离开迭代循环。现在您可以通过 CLI 或其他界面将命令添加到队列中,应用程序将做出相应的响应。
您甚至可以想像一下,添加时间戳来推迟命令执行。
PS:如果您正在执行群发邮件等任务,也许您会考虑将这些脚本移至命令行界面。我只是根据您关于“关闭浏览器”的评论才提到这一点。
可能需要一些工作,但它确实有效。
run()
将回调函数$job
作为参数。该函数代表您正在执行的任何批处理作业(群发邮件等)的单次迭代,并将$data
作为数据数组。每次迭代时,$job
都会被赋予$data
数组的下一个元素作为一组参数。您需要一些表(类似于 MySQL Workbench):
每当您想要暂停/恢复/中止作业时,请使用
job_id
和queue
表添加一行。 code>action(pause
、resume
或abort
),作业将做出响应。该作业将自动从队列表中删除已完成的命令。这就是它的要点。
If it's your own (self written) application, perhaps you should add some functionality that allows you to suspend or halt the execution.
One example would be on every X iterations, the script checks a resource for commands. If there are commands in the resource queue, it executes them in order, removes them and continues (if applicable).
For example, flat file or DB, you could add a
STOP-SUSPEND_EXECUTION
command. When your script reads that line or row out, it suspends normal execution but continues checking the resource periodically. After which if aRESUME
command is read, execution resumes from where it left off as it hasn't left the iterative loop.Now you can, either by CLI or other interface, add commands to the queue, and the application will respond accordingly.
You could even get fancy, adding timestamps to defer command execution.
PS: If you're performing tasks like mass mailing, etc., perhaps you'd consider moving these scripts to a command line interface. I mention this only based on your comment about "closing the browser".
Could use some work, but it does the trick.
run()
takes a callback function$job
as an argument. That function represents a single iteration of whatever batch job you're doing (mass mailing, etc.) and$data
as an array of data. With each iteration,$job
is given the next element of the$data
array as a set of arguments.You need some tables (a 'la MySQL Workbench):
Whenever you want to pause/resume/abort a job, add a row to the
queue
table with thejob_id
andaction
(pause
,resume
, orabort
) and the job will respond. The job will automatically remove the completed commands from thequeue
table.That's the gist of it.
如果您可以修改脚本,您可以在脚本的主循环中插入这样的一行(最好在
mail()
行之前):如果您关闭浏览器窗口,这将停止 PHP 脚本。尽管这是默认行为,php 通常无法立即停止脚本。
您可以在不了解脚本内部工作原理的情况下执行此操作,这比杀死 Apache 更好。
If you can modify the script you can insert a line like this in the main cycle of the script (preferably before the
mail()
line):This will stop the PHP script if you close the browser window. Although this is the default behavior php often fails to stop scripts right away.
You can do this without knowing much of the inner working of the script and it is nicer than killing Apache.
httpd
- 这将停止所有 Apache。httpd
- this will stop all of Apache.通常您会终止 Web 服务器。如果你运行 cgi exe 你可以杀死它。
Typically you would kill the web server. If you run the cgi exe you can kill that.
您是在问如何关闭疯狂的 php 脚本吗?如果是这样,你可以随时重新启动 apache。如果我误解了你的问题,我提前道歉。
Are you asking how to shut down a php script gone wild? If so you could always restart apache. If I misunderstood your question I apologize in advance.
编辑 php.ini 以在禁用功能中设置邮件。那么php将无法使用邮件功能。
http://www.php.net/manual/en /ini.core.php#ini.disable-functions
Edit your php.ini to set mail in the disabled-functions. Then php will fail to be able to use the mail function.
http://www.php.net/manual/en/ini.core.php#ini.disable-functions