php - Running thousands of MySQL queries, crashing server -
php - Running thousands of MySQL queries, crashing server -
i'm running stock update on our company website, , query follows;
$count = count($stock); for($i = 0; $i < $count; $i++) { if(strtolower($stock[$i]['stockloc']) == 'retail') { if($stock[$i]['avail'] < 0) { $stock[$i]['avail'] = 0; } mysql_query("update `xcart_products` set `avail` = ".$stock[$i]['avail']." `productid` in (select `productid` `xcart_extra_field_values` `productid` = ".$stock[$i]['productid']." , `fieldid` = 5 , lower(value) = 'retail')"); } }
eessentially runs in loop , iterates through thousands of products, updating stock levels. runs fine 4 minutes, things start lag on our website, mysql seems become backlogged other website db queries can't run (they appear locked), leads inevitable;
internal server error server encountered internal error or misconfiguration , unable finish request.
please contact server administrator inform of time error occurred , of might have done may have caused error.
more info error may available in server error log.
it doesn't seem timeout i've upped limit in php.ini no avail. query isn't particularly complex, run several one thousand times. maybe many 5000+. i'm not sure problem is, ran similar update scheme on our old website, , although wasn't 1 designed, didn't have problem uploading many stock quantity changes.
i'll happy expand question if farther info needed, honestly, i'm @ bit of loss how trace problem.
the $stock array associative array has next format;
array ( [0] => array ( [avail] => 55 [productid] => 17761 [sku] => aer-touch-2100 [stockloc] => retail ) [1] => array ( [avail] => 166 [productid] => 22653 [sku] => cas-aer-112 [stockloc] => retail ) [2] => array ( [avail] => 272 [productid] => 22952 [sku] => cas-ant-001 [stockloc] => retail ) [3] => array ( [avail] => 5 [productid] => 22956 [sku] => cas-ant-005 [stockloc] => retail ) [4] => array ( [avail] => 12 [productid] => 22958 [sku] => cas-ant-007 [stockloc] => retail
i have tried running delay every x iterations of loop, i'm still getting 500 internal server error message. need improve solution updating table.
php mysql
Comments
Post a Comment