防止PHP大请求超时

发布于 2024-09-26 20:39:02 字数 1104 浏览 1 评论 0原文

我正在向 Brightcove 服务器发出一个大请求,要求对我的视频中的元数据进行批量更改。似乎只进行了 1000 次迭代,然后就停止了 - 任何人都可以帮助调整此代码以防止超时发生吗?它需要进行大约 7000/8000 次迭代。

<?php
include 'echove.php';

$e = new Echove(
    'xxxxx',
    'xxxxx'
);

// Read Video IDs
# Define our parameters
$params = array(
    'fields'         => 'id,referenceId'

);

# Make our API call
$videos = $e->findAll('video', $params);


    //print_r($videos);
    foreach ($videos as $video) {

        //print_r($video);
        $ref_id = $video->referenceId;
        $vid_id = $video->id;

        switch ($ref_id) {
            case "":
                $metaData = array(
                    'id' => $vid_id,
                    'referenceId' => $vid_id
                );

                # Update a video with the new meta data
                $e->update('video', $metaData);                
                echo "$vid_id updated sucessfully!<br />";
                break;
            default:
                echo "$ref_id was not updated. <br />";
                break;
        }
    }
?>

谢谢!

I'm making a large request to the brightcove servers to make a batch change of metadata in my videos. It seems like it only made it through 1000 iterations and then stopped - can anyone help in adjusting this code to prevent a timeout from happening? It needs to make about 7000/8000 iterations.

<?php
include 'echove.php';

$e = new Echove(
    'xxxxx',
    'xxxxx'
);

// Read Video IDs
# Define our parameters
$params = array(
    'fields'         => 'id,referenceId'

);

# Make our API call
$videos = $e->findAll('video', $params);


    //print_r($videos);
    foreach ($videos as $video) {

        //print_r($video);
        $ref_id = $video->referenceId;
        $vid_id = $video->id;

        switch ($ref_id) {
            case "":
                $metaData = array(
                    'id' => $vid_id,
                    'referenceId' => $vid_id
                );

                # Update a video with the new meta data
                $e->update('video', $metaData);                
                echo "$vid_id updated sucessfully!<br />";
                break;
            default:
                echo "$ref_id was not updated. <br />";
                break;
        }
    }
?>

Thanks!

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

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

发布评论

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

评论(3

泼猴你往哪里跑 2024-10-03 20:39:02

尝试使用 set_time_limit() 函数。调用 set_time_limit(0) 将删除脚本执行的任何时间限制。

Try the set_time_limit() function. Calling set_time_limit(0) will remove any time limits for execution of the script.

哽咽笑 2024-10-03 20:39:02

还可以使用 ignore_user_abort() 绕过浏览器中止。即使您关闭浏览器,脚本也会继续运行(谨慎使用)。

Also use ignore_user_abort() to bypass browser abort. The script will keep running even if you close the browser (use with caution).

旧瑾黎汐 2024-10-03 20:39:02

尝试时不时地发送“状态:102 正在处理”,以防止浏览器超时(最好的时间间隔约为 15 到 30 秒)。处理请求后,您可以发送最终响应。

这样浏览器就不会再超时了。

Try sending a 'Status: 102 Processing' every now and then to prevent the browser from timing out (your best bet is about 15 to 30 seconds in between). After the request has been processed you may send the final response.

The browser shouldn't time out any more this way.

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