我運行這段代碼:立即mysqli_query停止執行PHP〜100,000行
<?php
$dbport = 1578;
$dbhost = "localhost";
$dbname = "dbname";
$dbuser = "dbuser";
$dbpswd = "dbpswd";
$MySQLLink = mysqli_connect($dbhost, $dbuser, $dbpswd, $dbname, $dbport);
$query = "SELECT * FROM assets_advanced_records LIMIT 100000";
echo "running query ".$query."<br>";
$result = mysqli_query($MySQLLink, $query) or die("Query failed (".$query."): ".mysqli_error($MySQLLink));
echo "query succeeded<br>";
mysqli_close($MySQLLink);
?>
停止執行mysqli_query();該頁面不再加載。
輸出看起來是這樣的:
running query SELECT * FROM assets_advanced_records LIMIT 100000
如果我減少限制設置爲10000我得到正確的輸出:
running query SELECT * FROM assets_advanced_records LIMIT 10000
query succeeded
可能是什麼造成的?
MySQL版本:5.7.12-0ubuntu1.1
PHP版本:7.0.8-0ubuntu0.16.04.3
我得到這個在控制檯執行停止時:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
UPDATE:
檢查/var/log/apache2/error.log我得到這樣的錯誤:
[Fri Dec 30 15:13:23.983920 2016] [:error] [pid 1907] [client 10.10.6.116:54978] FastCGI: server "/usr/lib/cgi-bin/php7-fcgi" stderr: PHP message: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 806912 bytes) in /var/www/html/debug_tools2.php on line 491, referer: http://10.10.6.24/debug_tools2.php
您是否試圖在單頁中打印所有100000條記錄? –
如果是這樣,你可以使用分頁這 –
不,我只是有點擔心查詢不失敗或超時,但只是停止執行(這似乎不像正常行爲)。上面的代碼是專門爲測試這個問題編寫的。我實際上並不需要運行該查詢,但我需要知道爲什麼它在未來出現時無法運行。 – ChelseaB