0
첫 번째 스크립트에 대한 결과 만 표시됩니다. 그러나 두 PHP 스크립트 모두에 대한 응답을 하나의 출력으로 보내고 싶습니다. 내가 개발중인 프로그램에서 여러 원격 서버를 쿼리하고 있습니다. 다른 서버에서 정보를 검색하고 그 결과를 하나의 응답으로 반환해야합니다.2 개의 PHP 스크립트 출력 결과를 병합하는 방법
<?php
// build the individual requests as above, but do not execute them
$ch_1 = curl_init('http://lifesaver.netai.net/example/pharm.php');
$ch_2 = curl_init('http://192.168.1.2/example/pharm.php');
curl_setopt($ch_1, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch_2, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch_1, CURLOPT_POST,1);
curl_setopt($ch_2, CURLOPT_POST,1);
curl_setopt($ch_1, CURLOPT_POSTFIELDS, "name=$value");
curl_setopt($ch_2, CURLOPT_POSTFIELDS, "name=$value");
// $_POST["name"]
// build the multi-curl handle, adding both $ch
$mh = curl_multi_init();
curl_multi_add_handle($mh, $ch_1);
curl_multi_add_handle($mh, $ch_2);
// execute all queries simultaneously, and continue when all are complete
$running = null;
do {
curl_multi_exec($mh, $running);
} while ($running);
// all of our requests are done, we can now access the results
$response_1 = curl_multi_getcontent($ch_1);
$response_2 = curl_multi_getcontent($ch_2);
echo $response_1;
echo $response_2;
?>