Home  >  Article  >  Backend Development  >  Summary of communication methods between PHP program and server side_PHP tutorial

Summary of communication methods between PHP program and server side_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:23:20890browse

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:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446848.htmlTechArticleSuppose there are 10 websites distributed in various places. Their inventories need to be synchronized, but the database does not support remote connections. If we want to obtain the server's inventory in real time, we can use many methods,...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn