cURL选项与php不兼容

cURL选项与php不兼容,php,curl,Php,Curl,我一直在写一些php脚本 $gettarget = $argv[2]; echo "Trying to do something . . .\n"; sleep(2); $ch = curl_init($gettarget); // initialize curl with given url $useragent = "Some user agent "; curl_setopt($ch, CURL

我一直在写一些php脚本

$gettarget = $argv[2];
echo "Trying to do something . . .\n";
            sleep(2);
            $ch = curl_init($gettarget); // initialize curl with given url
            $useragent = "Some user agent ";
            curl_setopt($ch, CURLOPT_USERAGENT, $useragent); // add useragent

            $response = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
echo $response;
echo "Done";

这里是发生的事情,它涉及到“尝试做一些事情”,然后什么都没有发生,完成的事情没有得到回应,这意味着curl有问题,我真的不知道curl出了什么问题,所以我想我会在这里发布。

在这个代码块中,您还没有执行curl。需要一个
$response=curl\u exec($ch)在末尾

    $gettarget = $argv[2];
    echo "Trying to do something . . .\n";

    sleep(2);
    $ch = curl_init($gettarget); // initialize curl with given url
    $useragent = "Some user agent ";
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent); // add useragent

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // setopt() does not exec()

    // write the response to a variable
    $response = curl_exec( $ch );

    echo $response;
    echo "Done";

$response=curl\u setopt($ch,CURLOPT\u RETURNTRANSFER,true)

应该是

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

调用
curl\u setopt()
告诉它在调用
curl\u exec()

您尚未在此代码块中执行curl时返回响应。需要一个
$response=curl\u exec($ch)结尾。你是说curl_exec()?是的,请看下面的答案并旋转它。我旋转了,但它仍然没有通过卷曲