PHP fails to complete a loop
I have a table with about 450,000 row. The table needs some derived fields updated.
My loop is:
$sql = "SELECT * FROM table_name";
if (!($r = @ mysql_query($sql, $db_connection))) die("Mysql query $sql . Error " . mysql_errno() . " : " . mysql_error());
while ($row = mysql_fetch_assoc($r))
{
// do a number of开发者_如何学C calculations, which create some $sql to update the record
$sql .= " WHERE p_id = $id"; // $id is the records id
if (!($result = @ mysql_query($sql, $db_connection))) die("Mysql query $sql . Error " . mysql_errno() . " : " . mysql_error());
}
This code is not getting through all the records. The php script is called from within a web page, and the web page does not respond. When I look at the table it has updated about 60,000 and the rest fo the records are un-tounched.
This used to work fine, but since I upgrade Ubuntu to the latest version this is happening. I tried increasing memory in php.ini but that has not worked.
Ideas anyone?
You could be hitting the PHP max execution time. To see if this is the case, look inside the web server log file. Look for something like this at the end:
PHP Fatal error: Maximum execution time of 30 seconds exceeded in ...
If that's it, you can edit your php.ini to have a longer timeout:
max_execution_time = 9999
If that wasn't it, the server log may still be able to tell you why the script is stopping.
You might need to increase the time limit of the page, by using set_time_limit($seconds);
or the max_execution_time
parameter in php.ini
You should also increase the execution time limit in your php.ini. The problem is likely that your script is taking too long to run.
精彩评论