php使用curl抓取qq空间的访客信息示例(16)

public function __construct($file, $visitor_capture_interval)
    {
        parent::__construct($file);
        $this->config = $this->extractFile();
        $this->visitor_capture_interval = $visitor_capture_interval;
    }

public function  updateConfig($arr)
    {
        $this->config = $this->extractFile();
        if ($this->isValidateRun()) {
            $fp = fopen($this->file, 'w');
            if (flock($fp, LOCK_EX)) {
                fwrite($fp, json_encode(array_merge($this->config, $arr)));
                flock($fp, LOCK_UN);
            }
            fclose($fp);
            return true;
        }
        return false;
    }

public function  getConfig($item)
    {
        if (is_array($this->config) && array_key_exists($item, $this->config)) {
            return $this->config[$item];
        }
        return null;
    }

public function isValidateRun()
    {
        $c_time = Utils::getMicroTime();
        $run_at_time = floatval($this->getConfig('run_at_time'));
        if ($c_time - $run_at_time >= $this->visitor_capture_interval) {
            return true;
        } else {
            return false;
        }
    }
}

class VisitorList extends BaseConfigFileUtils
{
    protected $visitor_list;

/**$visitor_list [] = array(
    'uin' => $visitor['uin'], 'name' => $visitor['name'], 'online' => $visitor['online'], 'time' => $visitor['time'],
    'img' => $visitor['img'], 'yellow' => $visitor['yellow'], 'supervip' => $visitor['supervip'],
    );**/

public function __construct($file)
    {
        parent::__construct($file);
        $this->visitor_list = $this->extractFile();
    }

public function updateVisitor($visitor)
    {
        if (is_array($visitor) && !empty($visitor)) {
            foreach ($visitor as $one) {
                array_unshift($this->visitor_list, $one);
            }
        }

$fp = fopen($this->file, 'w');
        if (flock($fp, LOCK_EX)) {
            fwrite($fp, json_encode($this->visitor_list));
            flock($fp, LOCK_UN);
        }
        fclose($fp);
    }

public function addVisitor($visitor)
    {
        $list = array();
        if (is_array($visitor) && !empty($visitor)) {
            foreach ($visitor as $one) {
                if (!$this->isVisitorExist($one['name'])) {
                    $list[] = $one;
                }
            }
            $this->updateVisitor($list);
        }

return $list;
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/6a3b396fe61b016e0da9eb2453f6669b.html