我沒有類似的東西,並用它捲曲:
$url = "http://secondserver.com?p=SOMESECRET";
$post['data[expire]'] = '2014-07-04';
$post['data[date]']= date("d.m.Y", time());
$post['data[count]']= $data['count'];
//initialize session
$ch = curl_init($url);
//the generated pdf from the external server
$tmppdf = tempnam($_SERVER['DOCUMENT_ROOT']."/cache/","pdf");
$fp = fopen($tmppdf, "a+b");
//session options
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
//curl_setopt($ch, CURLOPT_HEADER, false);
//execute the request
curl_exec($ch);
//close the session and filepointer
curl_close($ch);
fclose($fp);
,並在服務器第二服務器端:
$privateKey = "SOMESECRET";
if($privateKey != $_GET['p']) return;
$yourPassedData = $_POST['data'];
和你做。
附加:
如果您想直接服務從您可以使用以下組合的另一臺服務器的響應:
$post['data[headers]'] = getallheaders();
//initialize session
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return $response;
對於要取請求頭的部分,請參考:
http://php.net/manual/en/function.getallheaders.php
儘管您的解決方案在許多情況下確實非常方便,但在某些特殊情況下,我需要通過優化的PHP來提供請求,這意味着我需要將請求從第一臺服務器的apache傳遞到第二臺服務器的PHP是優化的),因爲PHP的第一臺服務器缺少所需的擴展/功能 –
好吧,我想我明白你的問題。您想要分析請求的http頭並從優化的服務器發送相應的響應。 也許你可以將你的頭部作爲有效載荷傳遞給其他服務器並在那裏處理這些東西? –
我需要更多的解釋從你身邊。你能編輯你的答案嗎?另外還有一些mod_proxy的考慮 –