【问题标题】:Apache / PHP - curl module not properly executedApache / PHP - curl 模块未正确执行
【发布时间】:2013-07-29 10:30:45
【问题描述】:

我在 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 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"

【问题讨论】:

    标签: php curl apache2 config modx


    【解决方案1】:

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

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

    在这里找到的解决方案: PHP Curl does not work on localhost?

    【讨论】:

      猜你喜欢
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-11
      • 2020-01-30
      • 2019-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多