我写了这样的代码(我使用 MySQL、PDO、InnoDB、Laravel4、localhost 和 MAC):
$all_queue = Queue1::all()->toArray(); //count about 10000
ob_end_clean();
foreach($all_queue as $key=>$value) {
$priceCreate=array(...);
Price::create($priceCreate);
Queue1::where('id',$value['id'])->delete();
}
这对我有用(使用 65mg 内存),但是当它运行时,我程序的其他部分(例如其他表)不起作用。我什至无法在 mysql 上打开我的数据库。我的程序和我的 sql 等待,当过程完成时,它们工作。
我不知道我该怎么办。 我认为这不适用于 laravel,这是针对我的 php 或 mysql 配置。
最佳答案
我想
$all_foreach($all_queue as $key=>$value) {
是
foreach($all_queue as $key=>$value) {
并且您没有错误(您已在应用配置中将 debug 设置为 true)。 尽量不要为您的脚本设置时间限制。
在你的 php.ini 中
max_execution_time = 3600 ;this is one hour, set to 0 to no limit
或者在代码中
set_time_limit(0)
如果是内存问题,请尝试释放内存并取消设置未使用的变量。我不建议在长脚本中释放空间。
...
}//end foreach loop
unset($all_queue); //no longer needed, so unset it to free memory
关于mysql - 我可以在 Laravel 中执行多个 MySQL 工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29874431/