开发者

PHP CLI or PHP over Apache for long running tasks

开发者 https://www.devze.com 2023-03-26 09:36 出处:网络
I need to run series of PHP scripts and process tasks that are in queue. A task could take upto 10 minutes or more when running from PHP Cli or PHP/Apache. There could be multiple instances of the scr

I need to run series of PHP scripts and process tasks that are in queue. A task could take upto 10 minutes or more when running from PHP Cli or PHP/Apache. There could be multiple instances of the scripts. This needs to happen repeatedly. The PHP/Apache will have 开发者_如何学PythonNO user interaction, they will be interacted with a backend /usr/bin/curl program.

I know that PHP-Cli will need to load the PHP interpreter and all its modules each time a script is run; whereas in PHP/Apache, they are loaded previously, so technically PHP/Apache should be a bit faster and consume lesser memory (as per other posts in SO)

Should I run these scripts via PHP CLI or via a dedicated Apache installed in the system just for background processing? So technically

# php processtask.php --taskId=1 &
# php processtask.php --taskId=2 &

VS

# /usr/bin/curl http://localhost/processtask.php?taskId=1 &
# /usr/bin/curl http://localhost/processtask.php?taskId=2 &

If loading curl each time could cause more resource usage then, I can use another daemon like script that loops and uses the curl library to do the same in different threads (this probably wont be PHP)


I'm using PHP, running CLI-based scripts to run in excess of one million items per day through various queues (and occasionally doing some multiples of that quantity). There are also some older systems that go via a webserver and the extra overhead of doing so can be hugely limiting when you are trying to do large numbers of tasks.

Web-based jobs will also have to have additional work put into them to avoid timing out. Running from the command line, or started via shell scripts and/or CRON would very much be the best way.


I think it's silly to install, configure, and maintain Apache for no other reason than to run offline PHP scripts. Think of all the extra requirements and bits that could go wrong. Keep it simple and use straight CLI.

Edit: Note also that you don't want just anybody to be able to fire off the process, so if you run through Apache, now you have to add a security layer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号