Youtube Zend Api Function Interrupts Script

醉酒当歌 提交于 2019-12-08 11:10:50

问题


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:


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.



来源:https://stackoverflow.com/questions/10378360/youtube-zend-api-function-interrupts-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!