how do I create a pause in the script?

I have written a script in php that uses php and mysql to check a column of thumbnails in my database.  The only issue is that since I am checking over 150,000 image URL's, the script keeps timing out.  I am notr using MYPHP ADMIN to execute the script, it is being strictly in PHP and MYSQL.  I am attaching the snippit of code so that yo ucan see and understand the loop to tel lme how to break it up.  I want the script to do it about 75 rows at a time.  To do 75 lines, close the database, reload the page, reopen the database, do another 75, close the database, reload the page, reopen the database, and so on......  Can you please show me how to change my script to accomplish this to avoid time-outs and to make the scipt run smoother?  Below is the script with sensitive data covered with **** and a brief description of each part.

<?php
$link = mysql_connect('localhost', '*****', '*****');
if (!$link) {die('Could not connect: ' . mysql_error());}
$db_selected = mysql_select_db('******');
if (!$db_selected) {
    die('Could not select database: ' . mysql_error());}
echo ("Connected successfully<BR>");
 
***Everything above just connects us to the database***
$query = ("SELECT *********** from ****************");
$result = mysql_query($query);
***Everything above gets THE DATA***
 
while($row = mysql_fetch_assoc($result))
      {$*************2 = $row['************'];
      $manu = substr($productcode2,0,3); 
	$part = substr($productcode2,3,30);
	$url= "http://www.*********.com/images/00/partimages/" . $manu . "/" . $part . ".jpg";              
	$imagetype = "image/jpeg";
***ABOVE GETS THE DATA INTO THE NEEDED VARIABLES WHILE IN THE LOOP***
 
       
            if($handle = fopen($url, "rb")){$content = fread($handle, 4);}
	      if(!$content ){$url = "http://www.*********.com/images/00/VendorPics/" . $manu . ".gif";}
		if($handle = fopen($url, "rb")){$content = fread($handle, 4);}
	      if(!$content ){$url = "http://www.***************.com/skin1/images/large_company_logo.gif";}
		
		
		$endchar = substr($url,-1);
		if($endchar == "f"){$imagetype = "image/gif";}		*****ABOVE  CREATES THE DATA NEEDED TO CREATE THE SQL COMMANDS.....STILL WITHIN THE LOOP****		
		
		$newquery1 = ("update `xcart_thumbnails` set `image_path` = '$url' where `productcode` = '$productcode2'");
		$newquery2 = ("update `xcart_thumbnails` set `image_type` = '$imagetype' where `productcode` = '$productcode2'");
***ABOVE CREATES THE ACTUAL SQL COMMANDS.....STILL WITHIN LOOP****
 
		echo"productcode2<BR>";
		mysql_query($newquery1);
		mysql_query($newquery2);
***EXECUTES ACTUAL SQL COMMANDS.....STILL WITHIN LOOP****
		
		$content=(!$content);}
***RESETS A VARIABLE ATTHE END OF THE LOOP AND ENDS LOOP******
 
 
mysql_close($link);
****CLOSES THE LINK TO THE DATABASE*****
?>

Open in new window

THE_HORSEPOWERSHOPAsked:
Who is Participating?
 
ionutz2k2Connect With a Mentor Commented:
You can try to use 'limit' in the sql query to select N rows. Store the indexes used (how many of the pictures parsed) in a SESSION variable reload the page and read the indexes nedded from the SESSION variable so you can continue from where you stoped before reloding.
The algorithm would go something like this:
- read index from SESSION (index is not set in session so initial index is 0)
- select and parse N images startying from row 0
- store N in the SESSION variable
- reload the page
---------------------
- read index from SESSION (index is N)
- select and parse N images starting from row N
- store 2*N in the SESSION variable
- reload the page

and so on...
0
 
ljubiccicaCommented:
Hey there!

Tried to use sleep() function?

http://www.php.net/sleep

KR,
ljubiccica
0
 
UmeshMySQL Principle Technical Support EngineerCommented:
0
 
THE_HORSEPOWERSHOPAuthor Commented:
I can't figure out how to get the pagination to work.  Is there any way I can get the script to go through line by line, rather than by doing a query, getting all 200,000 lines out of the database, and then trying to do it line by line.  My mysql server is not liking it at all!  LOL.  I would like to do it line by line.  Any suggestions?
0
All Courses

From novice to tech pro — start learning today.