Suppose there are 10 sites, distributed around them, with their inventory synchronized, and the database does not support remote connections.
We have to get the inventory of the server in real time, there are many ways to do it, and I know the following:
· Curl Way
· Socket mode
· SOAP methods in PHP5
The following examples are presented to implement it:
Curl Way
client.php
<?php
$psecode = ’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&pseid=" . $psecode .
"&amt=" . $amt;
curl_setopt($ch, CURLOPT_URL, $curl_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//不直接输出,返回到变量
$curl_result = curl_exec($ch);
$result = explode(’,’, $curl_result);
curl_close($ch);
print_r($result);
?>
The server side only needs to be output in a certain format, and then the client can receive it in this format as follows:
echo "OK," . $fpsecode . "," . $fbalance ;//以逗号分隔
Socket mode
This to rely on Third-party class library httpclient, you can download here: http://scripts.incutio.com/httpclient/
<?php
require_once ’class/HttpClient.php’;
$params = array(’web’ => ’www.abc.com’,
’pwd’ => ’123456’,
’action’ => ’check’,
’pseid’ => ’NDE005’,
’amt’ => 1);
$pageContents = HttpClient::quickPost(’http://ics.server.com/index.php’, $params);
$result = explode(’,’, $pageContents);
print_r($result);
?>