【问题标题】:CURL Command line to PHP?CURL 命令行到 PHP?
【发布时间】:2017-06-29 18:41:11
【问题描述】:

我需要在我的 CURL 脚本中运行 sudo ip netns exec protected curl

我不知道如何在 PHP 中做到这一点。

我在下面的 sn-p 中使用exec() 无济于事:

$options = array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_REFERER => $URL,
    CURLOPT_HTTPHEADER => array(
        'Accept-Language: ' . $Params
    )
);

$ch = curl_init($ReceiverURL);
curl_setopt_array($ch, $options);

$content = curl_exec($ch);

curl_close($ch);

return $content;

我做错了什么,我该如何实现?

【问题讨论】:

    标签: php ubuntu curl command-line


    【解决方案1】:

    你可以试试:

    system('sudo ip netns exec protected curl');
    

    【讨论】:

      【解决方案2】:

      我让它工作了,这就是我所做的,对于未来读到这个的任何人。 :)

            $descriptors = array(
                0 => array('pipe', 'r'), // STDIN
                1 => array('pipe', 'w'), // STDOUT
                2 => array('pipe', 'w')  // STDERR
            );
      
            $process = proc_open("sudo ip netns exec protected curl ".
                " --header \"Accept-Language: " . addslashes($Params) . "\" " . $ReceiverURL . ' -s 2>&1', $descriptors, $pipes);
      
            fclose($pipes[0]);
      
            $content = stream_get_contents($pipes[1]);
            fclose($pipes[1]);
      
            $error = stream_get_contents($pipes[2]);
            fclose($pipes[2]);
      
          return $content;
      

      【讨论】:

        猜你喜欢
        • 2013-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-29
        • 2013-08-25
        • 2015-03-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多