14,954
edits
| Line 119: | Line 119: | ||
** 跟檔案處理有關: | ** 跟檔案處理有關: | ||
*** (1) 減少每次讀取的資料行數,例如每次只讀取 50 行的資料筆數來做處理。 | *** (1) 減少每次讀取的資料行數,例如每次只讀取 50 行的資料筆數來做處理。 | ||
*** (2) | *** (2) 如果檔案較大,應避免使用一次讀取全部檔案內容的 [http://php.net/manual/en/function.file-get-contents.php file_get_contents]、[http://php.net/manual/en/function.file-put-contents.php file_put_contents]等函數、 | ||
*** (3) 如果透過 MySQL 執行匯出資料表的 CSV 檔案,則可以不要選擇欄位名稱,而是選擇全部欄位直接匯出。原因:「Rather than attempting to build the object-tree, you could directly try to select the result into a file」<ref>[https://stackoverflow.com/questions/31471186/how-to-export-millions-of-rows-from-mysql-to-csv-via-php-without-exhausting-memo How to export millions of rows from MySQL to CSV via PHP without exhausting memory? - Stack Overflow]</ref> | *** (3) 如果透過 MySQL 執行匯出資料表的 CSV 檔案,則可以不要選擇欄位名稱,而是選擇全部欄位直接匯出。原因:「Rather than attempting to build the object-tree, you could directly try to select the result into a file」<ref>[https://stackoverflow.com/questions/31471186/how-to-export-millions-of-rows-from-mysql-to-csv-via-php-without-exhausting-memo How to export millions of rows from MySQL to CSV via PHP without exhausting memory? - Stack Overflow]</ref> | ||
*** (4) 如果跟 json 檔案處理有關,可以搭配使用 [https://stedolan.github.io/jq/ jq] 可以有效處理大檔案的 json 檔案 | *** (4) 如果跟 json 檔案處理有關,可以搭配使用 [https://stedolan.github.io/jq/ jq] 可以有效處理大檔案的 json 檔案 | ||