2017-02-11 130 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;