2017-02-11 164 views
0

我需要在我的CURL脚本中运行sudo ip netns exec protected curlCURL命令行到PHP?

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

我在程式码中使用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; 

什么我做错了,我怎么能实现呢?

回答

0

你可以试试:

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

我得到它的工作,这是我做什么,在未来,读取任何人透露此事。 :)

 $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;