Swoole + mixphp + CodeIgniter to develop missing children information platform


This is my first article on SF. Write the missing children information platform based on spool, mixphp and CodeIgniter.

In 2017, we noticed that there is a “reunion system”, which is a special platform for the Ministry of public security to quickly spread the news of missing children, but the address of this platform was not found on the Internet. Of course, I accidentally found an interface on Taobao platform, which can get the data of missing children. Later, the interface prompted that it could not be accessed. So if I want to do such a missing children information platform, I have to get data from other places.

The full name of reunion system should be the emergency release platform for missing children information of the Ministry of public security. There is an official microblog account on Sina Weibo, through which missing children information can be released. Therefore, the first step in the implementation of “missing children information platform” is to get data from microblog, and the program to get data can finally run automatically in the background program, so there is no need for manual intervention.

Grab data from microblog page

I want to be familiar with PHP language, so when I plan to implement this idea by myself, I choose PHP. In addition, I also pay attention to spool before, which expands the scope of PHPer’s ability and is no longer limited to web development. Then we find a framework mixphp based on spool which is easy to use. Therefore, the program to capture data from microblog is based on mixhp. The engineering structure is as follows:
Swoole + mixphp + CodeIgniter to develop missing children information platform

Create a new controller, indexcontroller.php, in the apps / daemon / commands directory. The controller code is as follows:

 * Created by PhpStorm.
 * User: luoam
 * Date: 2018/4/20
 * Time: 22:28

namespace apps\daemon\commands;

use mix\client\Http;
use mix\console\Controller;
use mix\swoole\Process;
use apps\daemon\commands\SaeTClientV2;
use apps\daemon\commands\SaeTOAuthV2;
use apps\daemon\commands\Sae;

class IndexController extends Controller
    //Start up
    public function actionStart()
        //Repeat start processing
        if ($pid = Process::getMasterPid(self::PID_FILE)) {
            return "mix-daemon '{$this->processName}' is running, PID : {$pid}." . PHP_EOL;
        //Start up提示
        echo "mix-daemon '{$this->processName}' start successed." . PHP_EOL;
        //Metamorphosis into a guardian process
        if ($this->d) {
        //Write PID file
        //Modify process name
        Process::setName("mix-daemon: {$this->processName}");
        //Get to work
    public function startWork()
        try {
            while (true) {

                //Real time acquisition once
                $sql = "select `itemid` from items where status=:status";
                $rows = \mix::app()->rdb->createCommand($sql)->bindParams([
                    'status' = >'missing '
                if (!empty($rows)) {
                    foreach ($rows as $row) {
                        //Collect a missing one,
                        //One more incremental acquisition
        } catch (\Exception $e) {
            sleep(10); //  Take a break to avoid 100% CPU error

Oh, I need to remind you that mixppp needs some preparation conditions, which are very detailed in the official documents. After installing mixphp, you can directly run the above background program

./mix-daemon index/start -d

-D means that the process will run in the background.
Data capture is divided into several parts,

  1. Batch grab, in the first run of the program will be given some URL batch initialization grab
  2. Incremental crawling, according to the crawling back page content analysis of new URL, and then crawling new URL
  3. Supplementary crawling means that some of the children’s status is missing. If they are found after a period of time, their status will also change. Therefore, we need to carry out supplementary crawling for these URLs.

Front desk display page

The foreground display is equivalent to making a website, using the CodeIgniter framework, which is very convenient for making websites, so I have been using it.
The entire website only shows information about children who are still missing. The effect of the page is roughly as follows:
Swoole + mixphp + CodeIgniter to develop missing children information platform

The other is microblogging

I have registered an application in the microblog development platform, which can call the API of microblog, so in the data capture program, I will send a microblog when the data is saved in the database. The share interface is called. The process of using microblog API is as follows: first use OAuth to get access_ In addition, find the key and secret from the microblog development platform. Some codes are as follows:

$c = new SaeTClientV2(WB_AKEY, WB_SKEY, $access_token);
$sus = \mix::app()->rdb->insert('items', $dataArray)->execute();
$insertId = \Mix::app()->rdb->getLastInsertId();
$affectedRowss = \Mix::app()->rdb->getRowCount();
if ($affectedRowss > 0) {
    $texts = "" . $dataArray['name'] . "," . $dataArray['agesex'] . "," . mb_ Substr ($dataarray ['detail '], 0, 110,' UTF-8 ')...' ". If you have any clues, please contact the police immediately.". $dataarray ['policetel ']“ http://www.anman.org/index/baobei/ " . $containerid;
    if ($weibopic) {
        $weibopic = $this->get_img($weibopic, \mix::app()->getRuntimePath());
    $weiboRep = $c->share($texts, $weibopic);
    if (isset($weiboRep['id'])){
        $sinaweibos = array('itemid'=>$containerid,'weiboid'=>$weiboRep['id']);
    if ($weibopic){
    Echo date ("y-m-d H: I: s"). '' $containerid. 'microblog sent successfully! " PHP_ EOL;
    Echo date ("y-m-d H: I: s"). ', $containerid.' insert data successfully '. PHP_ EOL;
    \Mix:: app() - > log - > info (date ("y-m-d H: I: s"). ', $containerid.' insert data successfully ');
} else {
    \Mix:: app() - > log - > error (date ("y-m-d H: I: s"). ', $containerid.'Insert error');

The effect of microblogging is as follows:
Swoole + mixphp + CodeIgniter to develop missing children information platform

To sum up:

In the whole implementation process, we use the framework of spool, CodeIgniter, microblog development platform and mysql.
The background program grabs the data from the microblog to the local, and then sends the microblog through the microblog API according to the rules.
There is a special website to display this information.
Later, I’m going to try to do some analysis on these data.