CURL命令行到PHP?
我需要在curl脚本中运行CURL命令行到PHP?,php,ubuntu,curl,command-line,Php,Ubuntu,Curl,Command Line,我需要在curl脚本中运行sudo ip netns exec protected curl 我不知道如何在PHP中实现这一点 我在下面的代码段中使用了exec() $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_REFERER => $URL, CURLOPT_HTTPHEADER => array( 'Accept-Language: ' . $Params
sudo ip netns exec protected curl
我不知道如何在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;
我做错了什么?我如何才能做到这一点?您可以尝试:
system('sudo ip netns exec protected curl');
我让它发挥作用,这就是我所做的,为了将来读到这篇文章的人。:)
$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;