【问题标题】:curl works fine in command line, but not in phpcurl 在命令行中可以正常工作,但不能在 php 中
【发布时间】:2013-03-05 14:32:25
【问题描述】:

我使用 curl 从 PHP 中检索 url 的内容。它适用于大多数 url,但对于某些 url,它只返回一个空字符串(从命令行“卷曲”这样的 url 就可以了)。 这是我运行 curl 的方式:

$curl_session = curl_init($site->url);
curl_setopt($curl_session, CURLOPT_HEADER, 0);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT, TIMEOUT);
$output = curl_exec($curl_session);
curl_close($curl_session);

我也检查了,curl 似乎没有给出任何错误。

【问题讨论】:

  • 您确认$site->url 的值有效吗?
  • 你确定它是一个空字符串而不是布尔假吗? if ($output === FALSE) { die(curl_error($curl_session)); }
  • 是的,约翰,我什至用 url 的字面值替换了它,它仍然不起作用。
  • $output 的值为 string(0) ""
  • 这里有同样的问题。我的“输出”说:curl: (7) Failed to connect to <ip-address>: Permission denied。在命令行上使用 curl 时效果很好。 (我的 php 脚本实际上运行另一个 shell 脚本,然后从内部运行 curl)。

标签: php curl


【解决方案1】:

你可以使用

echo shell_exec("www.example.com");

【讨论】:

    猜你喜欢
    • 2017-05-07
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 2012-09-05
    • 2017-11-06
    相关资源
    最近更新 更多