Youtube Zend Api Function Interrupts Script

2019-06-13 12:53发布

This is the code:

...
require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Uri_Http');
$yt = new Zend_Gdata_YouTube();
$videoEntry = $yt->getVideoEntry($id_video);
....

In this script's few lines, SOMETIMES (I didn't understand why this keep happening just some times, and not in others, seemingly random) Zend_Gdata_YouTube() or getVideoEntry($id_video) doesn't return, and the script dies. In the script's folder there are no log files, so I don't understand what does it happen at run time. Any help or suggest would be appreciated,thanks.

1条回答
别忘想泡老子
2楼-- · 2019-06-13 13:31

I ran into the same problem, but with uploading youtube videos. By digging around in the Zend files, I found where the script dies. It is in Zend/Gdata/HttpAdapterStreamingSocket.php:

while ($chunk !== FALSE) {
    if (! @fwrite($this->socket, $chunk)) {
        require_once 'Zend/Http/Client/Adapter/Exception.php';
        throw new Zend_Http_Client_Adapter_Exception(
            'Error writing request to server');
    }
    $chunk = $body->read(self::CHUNK_SIZE);
}

By removing the @ from fwrite, I got the maximum execution time exceeded error. By disabling the execution time limit for the loop, the error didn't come up again:

$executionTime = ini_get('max_execution_time');
set_time_limit(0);
while ($chunk !== FALSE) {
    if (! fwrite($this->socket, $chunk)) {
        require_once 'Zend/Http/Client/Adapter/Exception.php';
        throw new Zend_Http_Client_Adapter_Exception(
            'Error writing request to server');
    }
    $chunk = $body->read(self::CHUNK_SIZE);
}
set_time_limit($executionTime);

This may not be your exact problem, but try to look in the Zend files for @fwrite calls and do the same thing, because your script is probably dying while writing chunks to the socket, and on a function that suppresses errors.

查看更多
登录 后发表回答