[英]CURL Command line to PHP?
I need to run sudo ip netns exec protected curl
in my CURL script. 我需要在CURL脚本中运行
sudo ip netns exec protected curl
。
I can't figure out how to do this in PHP. 我不知道如何在PHP中执行此操作。
I use exec()
as in the snippet below to no avail: 我在下面的代码段中使用
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;
What am I doing wrong and how can I achieve it? 我在做什么错,如何解决?
你可以试试:
system('sudo ip netns exec protected curl');
I got it to work, this is what I did, for anyone in the future that reads this. 我得到了它的帮助,这就是我所做的,对于以后阅读此内容的任何人。 :)
:)
$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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.