Suppose there are 10 Websites distributed across regions, their inventory needs to be synchronized, and the database does not support remote connection. To obtain the server inventory in real time, we can use the following methods:
· CURL Method
· SOCKET mode
· SOAP method in PHP5
The following are examples to implement it:
CURL Method
Client. php
<? Php $ Response code = 'nde005 '; $ Website = 'www .abc.com '; $ Amt = 1; $ Pwd = 123456; $ Ch = curl_init (); $ Curl_url = "http://ics1.server.com/index.php? Web = ". $ website. "& Pwd =". $ pwd. "& action = check & Consumer id =". $ response code. "& Amt =". $ amt; Curl_setopt ($ ch, CURLOPT_URL, $ curl_url ); Curl_setopt ($ ch, CURLOPT_POST, 1 ); Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // no direct output is returned to the variable $ Curl_result = curl_exec ($ ch ); $ Result = explode (',', $ curl_result ); Curl_close ($ ch ); Print_r ($ result ); ?> |
The server only needs to output the data in a certain format, and then the client can receive the data in this format, for example:
Echo "OK,". $ fpsecode. ",". $ fbalance; // separated by commas
SOCKET mode
The third-party class library HttpClient can be downloaded here: