跟踪我的脚本安装

时间:2014-08-22 09:32:14

标签: php mysql pdo

我正在构建CMS / CRM,并希望让用户使用他们的数据库在他们的服务器上安装此软件。

我想跟踪该安装中的一些数据,例如版本,因此如果该安装已过期,我可以发送更新。就像Wordpress告诉你新版本可用时一样。

我还希望能够跟踪能够为安装收费的用户数量。

我正在使用PHP,MySQL(PDO)。

你能让我知道这个过程被称为什么,任何对这个过程的引用都会很棒。

1 个答案:

答案 0 :(得分:0)

在您的应用程序中,您可能拥有一系列您想要跟踪的数据;像这样的东西

$data = array(
  'domain' => 'http://example.com',
  'version' => '1.4.35',
  'date_added' => '2014-08-20', 
  'last_update' => '2014-08-22'
);

然后你可以向你的服务器发送一个请求,看看那里是否有新东西;使用cURL或任何其他方法发送HTTP请求

$curl = curl_init("http://your-server.com/your-service/");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); // convert it to JSON format

$json = curl_exec($curl);
curl_close($curl);

// this is your feedback, in JSON format
$response = json_decode($json, true);

最好在curl_close()电话

之前检查状态
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($status == 201){
    // ... all fine
}else{
    // otherwise, do something but don't use exit() or die() in this case
}

解码后的$response值看起来像这样

array(
  'some_key'     => 'some_value',
  'another_key'  => 'another_value'
  ...
);

现在,根据回复,向用户回复消息,如此

if(isset($response['some_key']) && $response['some_key'] == 'some_value')){
    echo "An update is out there, <a href=\"http://your-domain.com/update\">Check it out</a>";
}