Jump to content

[SOLVED] help with php + scripts that take awhile to execute


Recommended Posts

i have a year or two of experience with php but have found myself needing to write a fairly complex script and im not sure if what i need to do can be done with php.

 

i will give a bit of background first.

the goal here is to send out emails to a user based off 'recommended items' based off their search history from my site.

so i have 20k members and over a 5 million page records.

 

because of the complexity of finding a list of 'recommended items' i do not want this to execute all at one time, i would like to space things out. ( i dont wanna kill the server)

 

lets say i want to limit the execution of this script to 2k people per hour (maby low or high, i have no clue, just throwing a number out), firstly how would i limit this...

the next thing is say i want to log in 3 hours later and check the status of whats going on... how would i do that? i dont want to hit the page again and start the initial execution of the script again...

 

Thanks in advance

For executing only 2k people at a time use LIMIT.  Write a recursive function that passes in the start/finish positions and increment them by 2k.  If you can keep track of how long 2k records takes to process you can do something like this in pseudo: sleep() = (1 hour - time already executed). 

 

For your second problem, write to a log file and you can watch the -tail of it in actual run time (you have to do some research cause I forget the command for this).  Hope this helps.

that does help. didnt realize there was a sleep command in php :) - i suck -

so, lets say i wanted to execute this script from an admin panel, and then pause + resume. that possible?

 

Please read this.  sleep — Delay execution.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.