0

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 NO 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)

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Is it faster to run on CLI? Is there a way to configure it to run as a service?
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.