cshontz Posted April 7, 2008 Share Posted April 7, 2008 My goal is to use PHP to copy a few thousand jpgs's from old website to new website. It works, but after about one minute of looping, it restarts from the very beginning of the script. It doesn't throw an error, it just re-executes the script from the very beginning. $count goes back to 0, and the query starts anew. Essentially, an infinite loop. This does not occur on a specific database entry. It occurs on a random entry usually after one minute of looping. Does anyone have any suggestions? PHP 5.2.5 <?php $count = 0; $con = mysql_connect('localhost', 'user', 'pass'); if (!$con) die('Could not connect: ' . mysql_error()); mysql_select_db("database", $con); $sql = "SELECT * FROM cs_migrate LIMIT 300"; //will never get to 300 $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $t = time(); $count++; $dest = "migrate/" . $t . "_" . $count . ".jpg"; file_put_contents($dest, file_get_contents($row['image01'])); } mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/100025-file_get_contents-in-loop-script-restarts/ Share on other sites More sharing options...
cshontz Posted April 8, 2008 Author Share Posted April 8, 2008 Just realized this is a looping problem and not a problem with file_get_contents. I replaced the file_get_contents part of my script with sleep(5) and looped through basic query results. The script started over or "reset" after approximately 60 seconds of looping. My initial diagnosis was incorrect, but I'm still rather perplexed. What would cause script to reset after so much time is spent looping? Link to comment https://forums.phpfreaks.com/topic/100025-file_get_contents-in-loop-script-restarts/#findComment-511624 Share on other sites More sharing options...
cshontz Posted April 8, 2008 Author Share Posted April 8, 2008 There, I think I figured it out. Not bad - only took about 16 hours. That's not even a whole day. Whatever my problem was, it seemed to have something to do with output buffering. Perhaps I was trying to push too much data into the buffer, and weirdness ensued in the form the script simply starting over. I can't imagine I'd be the only one to have that problem though - and I certainly came up empty via Google and the forums. I forget how I figured it out. I think I just stared at it long enough. Link to comment https://forums.phpfreaks.com/topic/100025-file_get_contents-in-loop-script-restarts/#findComment-511701 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.