How can I run a program in the background (non blocking) with php?

无人久伴 提交于 2020-01-11 03:58:05

问题


I want to run a shell script in php, but this shell script takes a long time to execute (it has sleep in it), I don't want the web server to block when executing this script. I tried exec() and shell_exec() in php but the server stops until the shell script finishes!

I thought of doing fork in the shell script itself but I don't know how to do that. I just want the php script to call this shell script and continue working, I'm not waiting any result from the script.

I tried running the shell script in the background with & still get blocking :( Any help is highly appreciated.


回答1:


I solved the problem by adding

"> /dev/null 2>/dev/null &"

after the script name to the shell_exec() php function

Thanks



来源:https://stackoverflow.com/questions/3139177/how-can-i-run-a-program-in-the-background-non-blocking-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!