Jump to content

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


c0rnf3d

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.