我有一个脚本在PHP Drive API中使用了可恢复的上传原型,自从我实现它以来它已经工作了3到4个月。在星期六17,脚本停止工作,由于出现此问题,crontab没有运行脚本:
[17-Oct-2015 05:15:07 America/Chicago] PHP Fatal error: Uncaught exception 'Google_IO_Exception' with message 'HTTP Error: Unable to connect: 'fopen(): SSL: Broken pipe'' in /root/scriptEnCrontab/libs/src/Google/IO/Stream.php:141
Stack trace:
#0 /root/scriptEnCrontab/libs/src/Google/IO/Abstract.php(136): Google_IO_Stream->executeRequest(Object(Google_Http_Request))
#1 /root/scriptEnCrontab/libs/src/Google/Http/MediaFileUpload.php(164): Google_IO_Abstract->makeRequest(Object(Google_Http_Request))
#2 /root/scriptEnCrontab/respaldoDrive_cgi.php(183): Google_Http_MediaFileUpload->nextChunk('\x8EGu\xA9Y\xE9\xEEQ\x9B\xE1\xAD\x98Xw\xEB...')
#3 /root/scriptEnCrontab/respaldoDrive_cgi.php(96): insertFile(Object(Google_Client), Object(Google_Service_Drive), '/root/respaldo/...', 'RespaldoScripts...', '0B2Xiur2QhdC6fk...')
#4 {main}
thrown in /root/scriptEnCrontab/libs/src/Google/IO/Stream.php on line 141
经过一些调整,升级和安装cURL后,问题变为
[20-Oct-2015 18:57:21 America/Chicago] PHP Fatal error: Uncaught exception 'Google_IO_Exception' with message 'Couldn't resolve host 'www.googleapis.com'' in /root/scriptEnCrontab/libs/src/Google/IO/Curl.php:115
Stack trace:
#0 /root/scriptEnCrontab/libs/src/Google/IO/Abstract.php(136): Google_IO_Curl->executeRequest(Object(Google_Http_Request))
#1 /root/scriptEnCrontab/libs/src/Google/Http/MediaFileUpload.php(164): Google_IO_Abstract->makeRequest(Object(Google_Http_Request))
#2 /root/scriptEnCrontab/respaldoDrive_cgi.php(186): Google_Http_MediaFileUpload->nextChunk('C\x9D\t\xD9\x95\x1F\xAF\xF5!qJ\xCAq\x8CB...')
#3 /root/scriptEnCrontab/respaldoDrive_cgi.php(101): insertFile(Object(Google_Client), Object(Google_Service_Drive), '/root/respaldo/...', 'PaginasWeb.tgz', '0B2Xiur2QhdC6fk...')
#4 {main}
thrown in /root/scriptEnCrontab/libs/src/Google/IO/Curl.php on line 115
或
[26-Oct-2015 11:36:24 America/Chicago] PHP Fatal error: Uncaught exception 'Google_IO_Exception' with message 'Operation timed out after 100000 milliseconds with 0 bytes received' in /root/scriptEnCrontab/libs/src/Google/IO/Curl.php:115
Stack trace:
#0 /root/scriptEnCrontab/libs/src/Google/IO/Abstract.php(136): Google_IO_Curl->executeRequest(Object(Google_Http_Request))
#1 /root/scriptEnCrontab/libs/src/Google/Http/MediaFileUpload.php(164): Google_IO_Abstract->makeRequest(Object(Google_Http_Request))
#2 /root/scriptEnCrontab/respaldoDrive_cgi.php(187): Google_Http_MediaFileUpload->nextChunk('S\x98\x85\xC7\xFE\x0E\x8E8\xEE\xE9\n\xF9\x86{\x19...')
#3 /root/scriptEnCrontab/respaldoDrive_cgi.php(99): insertFile(Object(Google_Client), Object(Google_Service_Drive), '/root/respaldo/...', 'RespaldoScripts...', '0B2Xiur2QhdC6fk...')
#4 {main}
thrown in /root/scriptEnCrontab/libs/src/Google/IO/Curl.php on line 115
我似乎无法使用1.1.6,1.1.5或1.1.4版本,即使它已经安装了没有安装cURL的1.1.4版本。
编辑:现在我没有googleapis解决问题,但现在它始终是操作超时错误。这是我使用IPv4 CURL设置运行的详细信息:
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 308 Resume Incomplete
< X-GUploader-UploadID: AEnB2Uqz5qHxRUf_l-0Eg72_ZVU7fNQ-aMdzSQEzufNGQa2kPM55YHEru0NA3OJQNFidKV7NvUJDQNO9uhVad1q9xHxiTqtqMg
< Range: bytes=0-1992294399
< X-Range-MD5: 91233d77f053f5b383c37ddacf30c29d
< Content-Length: 0
< Date: Fri, 30 Oct 2015 17:21:27 GMT
< Server: UploadServer
< Content-Type: text/html; charset=UTF-8
< Alternate-Protocol: 443:quic,p=1
< Alt-Svc: quic=":443"; p="1"; ma=604800
* HTTP error before end of send, stop sending
<
* Closing connection #0
* About to connect() to www.googleapis.com port 443 (#0)
* Trying 216.58.217.42...
* connected
* Connected to www.googleapis.com (216.58.217.42) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: /root/scriptEnCrontab/libs/src/Google/IO/cacerts.pem
CApath: /etc/ssl/certs
* SSL connection using ECDHE-RSA-RC4-SHA
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.googleapis.com
* start date: 2015-10-21 22:31:24 GMT
* expire date: 2016-01-19 00:00:00 GMT
* subjectAltName: www.googleapis.com matched
* issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
* SSL certificate verify ok.
> PUT /upload/drive/v2/files?uploadType=resumable&upload_id=AEnB2Uqz5qHxRUf_l-0Eg72_ZVU7fNQ-aMdzSQEzufNGQa2kPM55YHEru0NA3OJQNFidKV7NvUJDQNO9uhVad1q9xHxiTqtqMg HTTP/1.1
Host: www.googleapis.com
Accept: */*
content-range: bytes 1992294400-2044723199/4840357256
content-type: application/json; charset=UTF-8
content-length: 52428800
我的PHP版本是5.4.45-0 + deb7u1,cURL版本是:7.26.0。感谢Francois目前的帮助。
答案 0 :(得分:5)
tl; dr在您的代码中添加:
$google_config = new Google_Config();
$google_config->setClassConfig('Google_IO_Curl', 'options',
array(
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
)
);
$google_client = new Google_Client($google_config);
长版:
您的脚本&#34;无法解析主机&#39; www.googleapis.com&#39;&#34;提示DNS问题。 &#34; www.googleapis.com&#34;具有IPv4和IPv6地址。我的猜测是谷歌或您自己的网络最近有变化或错误导致IPv6出现问题。上述代码强制将主机名解析为IPv4地址。
如果这不能解决您的问题,请从脚本的调试输出中提供相关部分。分享您的PHP和cURL版本。要启用Google PHP Drive API的cURL详细输出,请添加代码:
$google_config = new Google_Config();
$google_config->setLoggerClass('Google_Logger_File');
$google_config->setClassConfig('Google_IO_Curl', 'options',
array(
CURLOPT_VERBOSE => TRUE,
)
);
$google_client = new Google_Client($google_config);
您可以看到输出中使用的IP版本。比较:
* About to connect() to www.googleapis.com port 443 (#0)
* Trying 74.125.136.95... * connected
使用:
* About to connect() to www.googleapis.com port 443 (#0)
* Trying 2a00:1450:4013:c01::5f... * connected
通过Google搜索登陆此问题,因为我遇到了完全相同的问题。 crontab中的脚本昨天开始失败&#34;操作在100000毫秒后超时,收到0字节&#34;错误。虽然有些跑步成功,但我仍然不能100%确定原因。我已经像上面解释的那样强制使用IPv4,到目前为止还没有看到新的错误。