Home >Backend Development >PHP Tutorial >Summary of communication methods between PHP program and server side_PHP tutorial
Suppose there are 10 websites distributed in various places. Their inventories need to be synchronized, but the database does not support remote connections. We need to obtain the server's inventory in real time. We can use many methods. The ones I know of are the following:
·CURL method
·SOCKET method
·SOAP method in PHP5
The following are examples to implement it:
CURL method
client.php
<?php<br>$psecode = ’NDE005’;<br>$website = ’www.abc.com’;<br>$amt = 1;<br>$pwd = 123456;<br>$ch = curl_init();<br>$curl_url = "http://ics1.server.com/index.php?web=" . $website . <br>"&pwd=" . $pwd . "&action=check&pseid=" . $psecode . <br>"&amt=" . $amt;<br>curl_setopt($ch, CURLOPT_URL, $curl_url);<br>curl_setopt($ch, CURLOPT_POST, 1);<br>curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//不直接输出,返回到变量<br>$curl_result = curl_exec($ch);<br>$result = explode(’,’, $curl_result);<br>curl_close($ch);<br>print_r($result);<br>?> |
On the server side, just press a certain Format output, and then the client can receive it in this format, such as:
echo "OK," . $fpsecode . "," . $fbalance ;//separated by commas
SOCKET method
This requires the help of the third-party class library HttpClient, which can be downloaded here: