简体   繁体   English

命令行PHP curl无法正常工作?

[英]Commandline php curl not working?

Hello i have php for commandline and trying to execute a curl link, but it don't works! 您好,我有用于命令行的php,并尝试执行curl链接,但是它不起作用!

<?php 
$ch = curl_init("https://albinstuff.net"); 
$result = curl_exec($ch);

echo $result;
?>

It outputs nothing, not even an error ... 它什么也不输出,甚至没有错误...

I have enabled php_curl.dll extension ... 我已启用php_curl.dll扩展名...

Try this : 尝试这个 :

$url = 'http://yourUrl.com';
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_POST, 1);
//    curl_setopt ($ch, CURLOPT_POSTFIELDS, $xml_data); // use this for post fields
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_TIMEOUT, 10); 
$data = curl_exec ($ch);
curl_close ($ch);

curl by default OUTPUTS whatever it finds, unless you turn on the "return transfer" option. 默认情况下, curl输出,除非您打开“返回传输”选项。 As well, if curl fails, curl_exec will return a boolean false, which will print as an empty string. 同样,如果curl失败,curl_exec将返回一个布尔值false,它将打印为空字符串。

Try: 尝试:

$ch = curl_init(...);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if($result === false) {
    echo "Curl failed with error: ", curl_error($ch);
}
echo $result;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM