Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a large PHP Script?

Well basically I may want to execute a script that may take as much as 1 hours as well.

What I really want to do is Send SMS to my users using a third party API. So its basically like I supply my script with an array of phone numbers and fire the method to send SMS.

However assuming it take 5 seconds to send 1 SMS and I want to send 1000 SMS which is roughly 1 - 2 hours. I can't use set_time_limit() because I am on shared host.

One way to do this is store numbers in a session and execute each SMS and use javascript to refresh that page until end. This way I need to keep my browser open and the execution will stop if my Internet Connection is disconnected.

So, Is there any better way to do this ?

Hope I am clear enough to explain what I want? I want to execute a large script that may take hours to execute without getting timeout.

like image 568
Atif Avatar asked May 15 '10 15:05

Atif


People also ask

How long can a PHP script run?

Remember, the max execution time of a PHP script is 30 seconds.

How many ways in which PHP scripts can be executed which?

Executing PHP files ¶ There are three different ways of supplying the CLI SAPI with PHP code to be executed: Tell PHP to execute a certain file. Both ways (whether using the -f switch or not) execute the file my_script.


2 Answers

A PHP script executed from the command-line or from a shell script, cron job, etc. does not have a timeout.

For CLI-invoked scripts, even if you set the PHP script's timeout dynamically with the set_time_limit() function, it has no effect.

like image 73
Bill Karwin Avatar answered Sep 20 '22 17:09

Bill Karwin


PHP scripts running from the command line aren't affected by max_execution_time option.
So you don't have to worry at all.

like image 22
Your Common Sense Avatar answered Sep 17 '22 17:09

Your Common Sense