Well, basically I would like to execute a script that can take up to 1 hour.
What I really want to do is send an SMS to your users using a third party API So basically I supply my script with an array of phone numbers and set fire to the method for sending SMS.
While assuming that 1 SMS is sent to send 1 SMS and I have to send 1000 SMS which is approximately 1 - 2 hours. I can not use set_time_limit ()
because I am on a shared host.
One way to do this is store number in one session and execute each SMS and use Javascript to refresh it. This way I need to open my browser until the page ends. And if my internet connection is disconnected, the execution will stop.
So, is there a better way to do this?
Hope I'm clear enough to explain what I want? I want to execute a large script that can take hours to execute without getting the timeout.
If your host you, Cron jobs are the best solution, a cron job is basically a normal php script Which is automatically run by the web server at a specific time interval. For your needs, I will create a script running every 5 minutes and process your numbers in 100 batches (obviously you want to change the time interval and batch size to suit). This will load your server down and prevent you from having trouble with your hosting provider to harass the resources.
In order to track your script which batch should be processed, I will set a track_batch table
ID, date_run, start_arrack, and_record, final_rone
< P> Basically:- These columns should give you a good signal to face the problem: Check to see the last batch run date. If this is not the present date for the current batch (or whatever identifier you choose to use), then proceed
- If the current batch was to for the current date, Check the Last_Rone column to see if you have already finished the process at all the numbers.
- If you still have the number to process, then use the combination of MySQL with the LIMIT and start the end record to create the DB query that your script will use to obtain the next batch. Will do for me.
- Process your numbers
- Track from this batch_ Store all the information in the batch table
- If the number of numbers is less than the maximum returns, then you Have reached the end and can set the last_ column to 1.
Once you find your script, you have to set up cron job. Shared hosts have the possibility of having their own custom interface to do this, so perhaps they are working on your script once you ask the best people.
Comments
Post a Comment