A request, distributed to multiple servers at the same time,
The normal is: A ============> B
What you want to achieve now is:
--------------> C
A ======> B---------------> D
---------------> E
If it's a GET request, just process the URL request, but the POST request also needs to process the data,
Working with Data:
If it is a key-value pair, use $_request to get the entire key-value pair;
$post _data $_request; // a key-value pair is obtained from the entire request, and the result is an array;
If it is in a stream, then use:
$post _data file_get_contents ("Php://input");
Once the data has been obtained, the code is used to forward it, and curl is required:
* * $_server[' Request_uri ' can be used if it is necessary to judge by the incoming URL; Gets the part of the URL, after domain, such as: https://www.google.com/abc.php ==>/abc.php
<?PHP/** * Send a POST request, and data is a key-value pair form*/ functionSend_post ($url,$post _data) { $postdata=Http_build_query($post _data); $options=Array( ' http ' =Array( ' Method ' = ' POST ', ' header ' = ' content-type:application/x-www-form-urlencoded ', ' Content ' =$postdata, ' timeout ' = 15 * 60 ) ); $context=stream_context_create($options); $result=file_get_contents($url,false,$context); return $result; } /** * Send a POST request, and data is in the form of a stream*/ functionSend_post_content ($url,$postdata) { $options=Array( ' http ' =Array( ' Method ' = ' POST ', ' header ' = ' content-type:application/x-www-form-urlencoded ', ' Content ' =$postdata, ' timeout ' = 15 * 60 ) ); $context=stream_context_create($options); $result=file_get_contents($url,false,$context); return $result; } //forwarding a key-value pair request if(isset($_request) &&!Empty($_request)) { $url 1= "http://test1.php"; $url 2= "http://test2.php"; $request=$_request; EchoSend_post ($url 1,$request); /*Echo*/Send_post ($url 2,$request); } Else { //forward Stream Request $url 3= "http://test3.php"; $url 4= "http://test4.php"; $request=file_get_contents("Php://input");//$_request; EchoSend_post_content ($url 1,$request); /*Echo*/Send_post_content ($url 2,$request); }
PHP Implementation Request shunt