0

我在 Windows Server 2008 R2 上设置了 Apache2 并加载了 PHP 模块。我想执行以下 php 脚本:

$ch = curl_init('https://itunes.apple.com/us/rss/toppaidapplications/genre=36/limit=15/json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200000);
$string = curl_exec($ch);
curl_close($ch);

$arr = json_decode($string,true);
foreach($arr['feed']['entry'] as $val)
{
$var = $val['link']['0']['attributes']['href'];
echo $var;
}

当我使用我的 CMS (MODX) 加载它时收到此错误消息

 Warning: Invalid argument supplied for foreach() in C:\webserver\www\site1\core\cache\includes\elements\modsnippet\4.include.cache.php on line 15

我想我在 apache: httpd.conf 或 php.ini 中配置了一些错误,因为在我未设置的另一个网络服务器上,脚本运行良好。

phpinfo 告诉我 curl 已启用(PHP 版本 5.4.17)

curl
cURL support    enabled
cURL Information    7.30.0
Age     3
Features
AsynchDNS   Yes
Debug   No
GSS-Negotiate   Yes
IDN     No
IPv6    Yes
Largefile   Yes
NTLM    Yes
SPNEGO  Yes
SSL     Yes
SSPI    Yes
krb4    No
libz    Yes
CharConv    No
Protocols   dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
Host    i386-pc-win32
SSL Version     OpenSSL/0.9.8y
ZLib Version    1.2.7
libSSH Version  libssh2/1.4.2 

在运行脚本的网络服务器上,我运行的是较旧的 PHP 版本(PHP 版本 5.2.17)。这里 phpinfo 说:

curl
cURL support    enabled
cURL Information    libcurl/7.24.0 OpenSSL/1.0.0i zlib/1.2.5 

在我的 php.ini 中写了以下指向 php_curl.dll

extension="c:\webserver\php\ext\php_curl.dll"
4

1 回答 1

0

通过在脚本中添加以下内容来解决它

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

在这里找到解决方案: PHP Curl 在 localhost 上不起作用?

于 2013-07-29T10:56:28.970 回答