我正在尝试使用cakephp
将大量记录添加到我的数据库中(对于QR码链接系统)。
我的基本代码是这样的:
public function generateQrCodes($program_id = null, $amount = 10000)
{
//add entries into database & generate QR images
for ($i = 1; $i++; $i <= $amount) {
$this->_createQr($program_id, $i);
}
//generate ZIP file
}
private function _createQr($program_id, $number)
{
//save into database
$this->create();
$this->data['Qrcode']['program_id'] = $program_id;
$this->data['Qrcode']['qr'] = $number;
$saved = $this->save();
if ($saved) {
$this->_createQrImage($program_id, $number);
return true;
} else {
return false;
}
}
显然这次超时(大约900行后)。有人可以帮我找出一种方法来重写它,以便它不会超时(以某种方式将其分解成块)吗?
答案 0 :(得分:1)
需要多长时间:$ this-&gt; _createQrImage($ program_id,$ number); ?
您可以在shell中执行此操作,因此它不会超时..
http://book.cakephp.org/1.3/en/view/1107/Creating-Shells-Tasks
答案 1 :(得分:1)
或者,您可以将php.ini中的max_execution_time指令修改为更大的值。它的默认时间是30秒。如果您无法访问主php.ini,例如您在共享主机上,那么您可以在自己的目录中创建php.ini的本地副本,它将允许您覆盖您需要更改的那些指令。
http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time