Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

http - Prevent timeout during large request in PHP

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...