我在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
在运行脚本的Web服务器上,我运行的是较旧的PHP版本(PHP V5.2.17)。在这里phpinfo sais:
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"
答案 0 :(得分:0)
通过在脚本中添加以下内容来解决它
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
解决方案在这里找到: PHP Curl does not work on localhost?