[英]Execute PHP file in background
I have some php code, that execute for a very long time. 我有一些PHP代码,执行很长一段时间。
I need to realise next scheme: 我需要实现下一个方案:
I don't want to use exec command because 1000 users makes 1000 php processes. 我不想使用exec命令,因为1000个用户制作了1000个php进程。 It's not way for me...
这不适合我......
Use http requests to the local http server from within your script in combination with phps ignore_client_abort()
function. 在脚本中结合
ignore_client_abort()
函数使用对本地http服务器的http请求。
That way you keep the load inside the http servers worker processes, have a natural limit and queuing of requests comes for free. 这样您就可以将负载保留在http服务器工作进程中,具有自然限制并且请求的排队是免费的。
So you basically want a queue (possibly stored in a database) and a command line script ran by cron that process queued items. 所以你基本上想要一个队列(可能存储在数据库中)和cron运行的命令行脚本来处理排队的项目。
Clarification : I'm not sure about what's unclear about my answer, but this complies with the two requirements imposed by the question: 澄清 :我不确定我的答案有什么不清楚,但这符合问题所强加的两个要求:
You can use CLI to execute multiple PHP scripts 您可以使用CLI执行多个PHP脚本
or 要么
you can try Easy Parallel Processing in PHP 您可以在PHP中尝试Easy Parallel Processing
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.