我看到了这个问题:Problem with update pear说问题是使用了过时的PEAR版本,好吧,我使用的是1.9.4(最新版本)。
dinosaurhunter:~ root# pear -V
PEAR Version: 1.9.4
PHP Version: 5.3.21
Zend Engine Version: 2.3.0
Running on: Darwin dinosaurhunter.network.local 12.2.1 Darwin Kernel Version 12.2.1: Thu Oct 18 16:32:48 PDT 2012; root:xnu-2050.20.9~2/RELEASE_X86_64 x86_64
我正在使用自制软件中的PHP。
太奇怪了:
dinosaurhunter:~ root# pear upgrade
Error getting channel info from pear.php.net: Connection to `pear.php.net:80' failed: Operation timed out
Error getting channel info from pear.php.net: Connection to `pear.php.net:80' failed: Operation timed out
Error getting channel info from pear.php.net: Connection to `pear.php.net:80' failed: Operation timed out
Error getting channel info from pear.php.net: Connection to `pear.php.net:80' failed: Operation timed out
Error getting channel info from pear.php.net: Connection to `pear.php.net:80' failed: Operation timed out
Nothing to upgrade
dinosaurhunter:~ root# curl pear.php.net:80 | head -n5
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14420 0 14420 0 0 41953 0 --:--:-- --:--:-- --:--:-- 66759
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<link rel="alternate" href="http://blog.pear.php.net/feed/" type="application/rss+xml" title="PEAR News" /> <title>PEAR - PHP Extension and Application Repository</title>
<link rel="shortcut icon" href="/gifs/favicon.ico" />
我看到有些人说这是代理问题 - 我也不使用代理。
dinosaurhunter:~ root# pear config-show | grep -i proxy
HTTP Proxy Server Address http_proxy <not set>
我真的迷失了,因为他们说的网址工作正常,我没有使用代理,PEAR是最新的 - 还有什么呢?
编辑做了更多调试......
此代码有效:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set ('allow_url_fopen', 1);
$url = 'http://www.google.com';
// Create a stream
$opts = array(
'http'=>array(
'timeout'=>60,
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents($url, false, $context);
var_dump($file);
然而,这不起作用:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set ('allow_url_fopen', 1);
$file = file_get_contents('http://www.google.com/');
var_dump($file);
失败了:
警告:
file_get_contents(http://www.google.com/)
:无法打开流:操作超时
答案 0 :(得分:1)
最基本的问题是default_socket_timeout
配置。
设置如下:
; Default timeout for socket based streams (seconds)
; http://php.net/default-socket-timeout
default_socket_timeout = unlimited
我把它改成了
; Default timeout for socket based streams (seconds)
; http://php.net/default-socket-timeout
default_socket_timeout = 120
它有效。
看起来file_get_contents
可能不尊重“{3}}”无限制“的值。 Blargh!
答案 1 :(得分:0)
运行wireshark并检查pear实际上在网络方面做了什么。您还可以运行pear -vvvvvv
来获取调试输出 - 这可能会为您提供有关问题源的提示。