简体   繁体   中英

How do I code PHP Worker Processes?

I have a PHP script that needs to run some pretty hefty imagemagick commands.

These commands may be run at the same time by multiple users, so user a, b, c, and d would all be running the same task. I want to make it into a background process, so I can use jQuery, for example, to show a loading bar during processing.

What would be the best way to accomplish this? Or, is there another method that may be easier?

There are quite some guides how to create Deamons with PHP:
http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/

Or how to background a process:
http://waynepan.com/2007/10/11/how-to-use-ignore_user_abort-to-do-process-out-of-band/

You could create a deamon running in the background, reading from a database table that contains all jobs that need to be worked on and then you can check with your frontend process for that table every once in a while until all jobs have cleared for that specific process.

You can also use a message queue for that, so you can use multiple deamons in parallel (for example on multicore systems) without conflicting.

I seek for hours, at least, the solution was very easy for me using Cron Jobs . In cPanel you can go to Advanced -> Cron Jobs, and there schedule a task using a PHP script in Command line.

A Command example that execute a script php:

/usr/bin/wget http://www.example.com/miscript.php

or better:

php /home/USER/public_html/miscript.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM