Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Background Processes

I'm trying to make a PHP script, I have the script finished but it takes like 10 minutes to finish the process it is designed to do. This is not a problem, however I presume I have to keep the page loaded all this time which is annoying. Can I have it so that I start the process and then come back 10mins later and just view the log file it has generated?

like image 623
zuk1 Avatar asked Nov 05 '08 13:11

zuk1


People also ask

How do I stop a PHP script from running in the background?

If you started it in background use ps aux | grep time. php to get PID. Then just kill PID . If process started in foreground, use to interrupt it.

What processes run in the background?

A background process is a computer process that runs behind the scenes (i.e., in the background) and without user intervention. Typical tasks for these processes include logging, system monitoring, scheduling, and user notification.

How do I run a PHP script continuously?

Cron jobs are timed jobs that can for example execute a PHP script. You could set up a cron job to check which user should receive his/her sms every hour. Depending on your operating system you can set up these cron jobs. For linux distrubutions there are tons of guides on how to set this up.

What is the process of running PHP?

After installation of PHP, we are ready to run PHP code through command line. You just follow the steps to run PHP program using command line. Open terminal or command line window. Goto the specified folder or directory where php files are present.


1 Answers

Well, you can use "ignore_user_abort(true)"

So the script will continue to work (keep an eye on script duration, perhaps add "set_time_limit(0)")

But a warning here: You will not be able to stop a script with these two lines:

ignore_user_abort(true);  set_time_limit(0); 

Except you can directly access the server and kill the process there! (Been there, done an endless loop, calling itself over and over again, made the server come to a screeching stop, got shouted at...)

like image 64
bastiandoeen Avatar answered Oct 07 '22 07:10

bastiandoeen