尝试添加大量行时脚本超时

发布于 2024-12-27 17:04:01 字数 873 浏览 2 评论 0原文

我正在尝试使用 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 行之后)。有人可以帮我想出一种方法来重写它,这样它就不会超时(以某种方式将其分成块)吗?

I'm trying to add a large amount of records into my database using cakephp (for a QR Code linking system).

My base code goes like this:

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;
        }
    }

Obviously this times out (after about 900ish rows). Can someone help me work out a way to rewrite this so that it wont timeout (break it into chunks somehow)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独﹏钓一江月 2025-01-03 17:04:01

需要多长时间:$this->_createQrImage($program_id, $number); ?

您可以在 shell 中执行此操作,这样它就不会超时。

http://book.cakephp.org/1.3/en/view/1107/Creating-Shells-Tasks

How long it takes to : $this->_createQrImage($program_id, $number); ?

You could probably do this in a shell so it will not timeout..

http://book.cakephp.org/1.3/en/view/1107/Creating-Shells-Tasks

回忆凄美了谁 2025-01-03 17:04:01

或者,您可以将 php.ini 中的 max_execution_time 指令修改为更大的值。默认时间为 30 秒。如果您无权访问主 php.ini(例如您位于共享主机上),那么您可以在自己的目录中创建 php.ini 的本地副本,它将允许您覆盖需要更改的那些指令。

http://www.php.net/manual /en/info.configuration.php#ini.max-execution-time

Alternatively you can modify the max_execution_time directive in php.ini to a larger value. It's default time is 30 seconds. If you don't have access to the main php.ini such as you are on shared hosting then you can create a local copy of php.ini in your own directories and it will allow you to override those directives that you need to change.

http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文