我看到了这个问题: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>
我真的很迷茫,因为他们说的 URL 超时工作得很好,我没有使用代理,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/)
无法打开流:操作超时