任務命令行
-
~~~
<?php
/**
* @Author: 陳靜
* @Date: 2018/04/18 22:13:03
* @Description:
*/
namespace app\console;
use app\base\controller\Redis;
use think\Config;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Exception;
use think\Log;
/**
* Created by PhpStorm.
* Power by Mikkle
* QQ:776329498
* Date: 2017/6/12
* Time: 15:07
*/
class Task extends Command
{
protected $sleep = 10;
protected $redis;
protected $workerListName;
protected $pcntl;
public function __construct($name= null)
{
parent::__construct($name);
$this->redis=Redis::instance(Config::get("redis"));
$this->workerListName = "worker_list";//任務名(同執行命令時,插入hash中的任務名)
$this->pcntl =true;//是否開啟多進程處理任務
}
protected function configure()
{
$this->setName('task:queue')->setDescription('Here is the task\'s command ');
}
protected function execute(Input $input, Output $output)
{
while(true){
//標記后端服務運行中
$this->signWorking();
echo "==================================================".PHP_EOL;
$this->autoClass();
echo "==================================================".PHP_EOL;
$this->sleep();
}
}
/**
* @Author: 陳靜
* @Date: 2018/04/21 14:15:56
* @Description: 開始標記命令執行中,存入redis
*/
public function signWorking(){
$this->redis->set("command","true");
$this->redis->setExpire("command",10);
}
/**
* 自動執行
* Power: Mikkle
* Email:776329498@qq.com
* @return bool
*/
protected function autoClass()
{
$works = $this->getWorks();
if ($works) {
foreach ($works as $item => $work) {
if ($this->pcntl) {
$this->pcntlWorker($work, $item);
} else {
$this->runWorker($work, $item);
}
}
} else {
return false;
}
}
public function getWorks(){
try{
return $this->redis->hget($this->workerListName);
}catch (Exception $e){
return false;
}
}
/**
* 檢測執行方法是否存在
* Power: Mikkle
* Email:776329498@qq.com
* @param $work
* @param $item
* @return bool
*/
protected function checkWorkerExists($work,$item){
if (class_exists($work)){
if(method_exists($work,'run')){
return true;
}else{
return false;
}
}
}
/**
* 運行任務
* Power: Mikkle
* Email:776329498@qq.com
* @param $work
* @param $item
*/
protected function runWorker($work,$item){
try{
if($this->checkWorkerExists($work, $item)) {
echo "執行[{$work}]任務" . PHP_EOL;
$work::run();
Log::notice("執行[{$work}]任務");
}else{
echo "執行[{$work}]任務的run方法不存在".PHP_EOL;
$this->redis->hdel($this->workerListName,$item);
}
}catch (Exception $e){
echo "執行[{$work}]任務失敗" . PHP_EOL;
Log::notice($e->getMessage());
if ($this->pcntl) {
$this->pcntlKill();
}
}
}
/**
* 分進程
* Power: Mikkle
* Email:776329498@qq.com
* @param $work
* @param $item
*/
protected function pcntlWorker($work,$item)
{
try{
// 通過pcntl得到一個子進程的PID
$pid = pcntl_fork();
if ($pid == -1) {
// 錯誤處理:創建子進程失敗時返回-1.
die ('could not fork');
} else if ($pid) {
// 父進程邏輯
// 等待子進程中斷,防止子進程成為僵尸進程。
// WNOHANG為非阻塞進程,具體請查閱pcntl_wait PHP官方文檔
pcntl_wait($status, WNOHANG);
} else {
// 子進程邏輯
$pid_2 = pcntl_fork();
if ($pid_2 == -1) {
// 錯誤處理:創建子進程失敗時返回-1.
die ('could not fork');
} else if ($pid_2) {
// 父進程邏輯
echo "父進程邏輯開始" . PHP_EOL;
// 等待子進程中斷,防止子進程成為僵尸進程。
// WNOHANG為非阻塞進程,具體請查閱pcntl_wait PHP官方文檔
pcntl_wait($status, WNOHANG);
echo "父進程邏輯結束" . PHP_EOL;
} else {
// 子進程邏輯
echo "子進程邏輯開始" . PHP_EOL;
$this->runWorker($work,$item);
echo "子進程邏輯結束" . PHP_EOL;
$this->pcntlKill();
}
$this->pcntlKill();
}
}catch (Exception $e){
Log::error($e->getMessage());
}
}
/**
* Kill子進程
* Power: Mikkle
* Email:776329498@qq.com
*/
protected function pcntlKill(){
// 為避免僵尸進程,當子進程結束后,手動殺死進程
if (function_exists("posix_kill")) {
posix_kill(getmypid(), SIGTERM);
} else {
system('kill -9' . getmypid());
}
exit ();
}
public function sleep($second=""){
$second = $second ? $second : $this->sleep;
// sleep(sleep($second)); //TP5的命令行 sleep($second) 不生效
sleep($second);
echo "睡眠{$second}秒成功!當前時間:" . date('h:i:s') . PHP_EOL;
}
/**
* @return int
*/
public function getSleep()
{
return $this->sleep;
}
/**
* @param int $sleep
* @return void
*/
public function setSleep($sleep)
{
$this->sleep = $sleep;
}
}
~~~
worker基類源碼
-
~~~
<?php
/**
* @Author: 陳靜
* @Date: 2018/04/18 23:08:29
* @Description:
*/
namespace app\worker\controller;
use app\base\controller\Redis;
use think\Config;
abstract class Base
{
protected $redis;
protected $workerListName;
protected $workerName;
public static $instance;
/**
* Base constructor.
* @param array $options
*/
public function __construct($options=[])
{
$this->redis = $this->redis();
$this->workerListName = "worker_list";
$this->workerName = get_called_class();
}
/**
* redis加載自定義Redis類
* Power: Mikkle
* Email:776329498@qq.com
* @param array $options
* @return Redis
*/
protected static function redis($options=[]){
$options = empty($options) ? $redis = Config::get("redis") : $options;
return Redis::instance($options);
}
/**
* 標注命令行執行此任務
* Power: Mikkle
* Email:776329498@qq.com
*/
public function runWorker(){
$this->redis->hset($this->workerListName,$this->workerName,$this->workerName);
}
/**
* 標注命令行清除此任務
* Power: Mikkle
* Email:776329498@qq.com
*/
public function clearWorker(){
$this->redis->hdel($this->workerListName,$this->workerName);
}
/**
* Power: Mikkle
* Email:776329498@qq.com
* @param array $options
* @return static
*/
static public function instance($options=[]){
if (isset(self::$instance)){
return self::$instance;
}else{
return new static($options);
}
}
}
~~~
控制器,添加任務類
-
~~~
<?php
/**
* @Author: 陳靜
* @Date: 2018/04/20 22:54:12
* @Description:
*/
namespace app\worker\controller;
use think\Exception;
use think\Log;
class RecordLog extends Base
{
protected $options=[];
protected $listName;
public function __construct($options=[])
{
parent::__construct();
$this->listName = md5($this->workerName);
}
/**
* 檢測命令行是否執行中
* Power: Mikkle
* Email:776329498@qq.com
* @return bool
*/
static public function checkCommandRun(){
return self::redis()->get("command") ? true :false;
}
/**
* @Author: 陳靜
* @Date: 2018/04/21 14:48:09
* @Description: 將數據壓入棧中
* @param $data
* @param array $options
*/
static public function add($data,$options=[]){
$instance = self::instance($options);
//檢查命令是否執行中
// if (self::checkCommandRun()) {
$instance->redis->lpush($instance->listName, $data);
$instance->runWorker();
// }
}
/**
* 命令行執行的方法
* Power: Mikkle
* Email:776329498@qq.com
*/
static public function run(){
$instance = self::instance();
try{
$i = 0;
while(true){
$data = $instance->redis->rpop($instance->listName);
if ($data){
$re=$instance->sendMessage($data);
Log::notice($re);
}else{
break;
}
$i++;
sleep(1);
}
$instance->clearWorker();
echo "執行了{$i}次任務".PHP_EOL;
}catch (Exception $e){
Log::error($e);
$instance->clearWorker();
die($e->getMessage());
}
}
/**
* 發送模版消息的方法
* Power: Mikkle
* Email:776329498@qq.com
* @param $data
* @return bool
*/
protected function sendMessage($data){
$no = $data;
if ($no){
Log::notice("發送成功[{$no}]");
return true ;
}else{
Log::notice("發送失敗[{$no}]");
$this->failed($data);
};
}
/**
* 出錯執行的回調方法
* Power: Mikkle
* Email:776329498@qq.com
* @param $data
*/
protected function failed($data){
}
}
~~~
Redis類,使用的是mikkle的,感謝
-
~~~
<?php
namespace app\base\controller;
use think\Exception;
use think\Log;
/**
* Class Redis redis操作類,集成了redis常用的操作方法
*/
class Redis
{
public $redisObj = null;//redis實例化時靜態變量
static protected $instance;
protected $sn;
protected $index = 0;
protected $port = 6379;
protected $auth = "";
protected $host = "127.0.0.1";
public function __construct($options = [])
{
$host = trim(isset($options["host"]) ? $options["host"] : $this->host);
$port = trim(isset($options["port"]) ? $options["port"] : $this->port);
$auth = trim(isset($options["auth"]) ? $options["auth"] : $this->auth);
$index = trim(isset($options["index"]) ? $options["index"] : $this->index);
if (!is_integer($index) && $index > 16) {
$index = 0;
}
$sn = md5("{$host}{$port}{$auth}{$index}");
$this->sn = $sn;
if (!isset($this->redisObj[$this->sn])) {
try {
$this->redisObj[$this->sn] = new \Redis();
$this->redisObj[$this->sn]->connect($host, $port);
$this->redisObj[$this->sn]->auth($auth);
$this->redisObj[$this->sn]->select($index);
} catch (Exception $e) {
Log::notice($e->getMessage());
try {
$this->redisObj[$this->sn] = new \Redis();
$this->redisObj[$this->sn]->connect($host, $port);
$this->redisObj[$this->sn]->auth($auth);
$this->redisObj[$this->sn]->select($index);
} catch (Exception $e) {
Log::error($e->getMessage());
}
}
}
$this->redisObj[$this->sn]->sn = $sn;
$this->index = $index;
}
/**
* Power: Mikkle
* Email:776329498@qq.com
* @param array $options
* @return Redis
*/
public static function instance($options = [])
{
if (self::$instance == null){
return self::$instance = new Redis($options);
}
return self::$instance;
}
public function getKeys($key = '*')
{
return $this->redisObj[$this->sn]->getKeys($key);
}
public function setExpire($key, $time = 0)
{
if (!$key) {
return false;
}
switch (true) {
case ($time == 0):
return $this->redisObj[$this->sn]->expire($key, 0);
break;
case ($time > time()):
$this->redisObj[$this->sn]->expireAt($key, $time);
break;
default:
return $this->redisObj[$this->sn]->expire($key, $time);
}
}
/*------------------------------------start 1.string結構----------------------------------------------------*/
/**
* 增,設置值 構建一個字符串
* @param string $key KEY名稱
* @param string $value 設置值
* @param int $timeOut 時間 0表示無過期時間
* @return true【總是返回true】
*/
public function set($key, $value, $timeOut = 0)
{
$setRes = $this->redisObj[$this->sn]->set($key, $value);
if ($timeOut > 0) $this->redisObj[$this->sn]->expire($key, $timeOut);
return $setRes;
}
/**
* 查,獲取 某鍵對應的值,不存在返回false
* @param $key ,鍵值
* @return bool|string ,查詢成功返回信息,失敗返回false
*/
public function get($key)
{
$setRes = $this->redisObj[$this->sn]->get($key);//不存在返回false
if ($setRes === 'false') {
return false;
}
return $setRes;
}
/*------------------------------------1.end string結構----------------------------------------------------*/
/*------------------------------------2.start list結構----------------------------------------------------*/
/**
* 增,構建一個列表(先進后去,類似棧)
* @param String $key KEY名稱
* @param string $value 值
* @param $timeOut |num 過期時間
*/
public function lPush($key, $value, $timeOut = 0)
{
// echo "$key - $value \n";
$re = $this->redisObj[$this->sn]->LPUSH($key, $value);
if ($timeOut > 0) $this->redisObj[$this->sn]->expire($key, $timeOut);
return $re;
}
/**
* 增,構建一個列表(先進先去,類似隊列)
* @param string $key KEY名稱
* @param string $value 值
* @param $timeOut |num 過期時間
*/
public function rPush($key, $value, $timeOut = 0)
{
// echo "$key - $value \n";
$re = $this->redisObj[$this->sn]->RPUSH($key, $value);
if ($timeOut > 0) $this->redisObj[$this->sn]->expire($key, $timeOut);
return $re;
}
/**
* 查,獲取所有列表數據(從頭到尾取)
* @param string $key KEY名稱
* @param int $head 開始
* @param int $tail 結束
*/
public function lRanges($key, $head, $tail)
{
return $this->redisObj[$this->sn]->lrange($key, $head, $tail);
}
/**
* Power by Mikkle
* QQ:776329498
* @param $key
* @return mixed
*/
public function rPop($key)
{
return $this->redisObj[$this->sn]->rPop($key);
}
public function lPop($key)
{
return $this->redisObj[$this->sn]->lpop($key);
}
/*------------------------------------2.end list結構----------------------------------------------------*/
/*------------------------------------3.start set結構----------------------------------------------------*/
/**
* 增,構建一個集合(無序集合)
* @param string $key 集合Y名稱
* @param string|array $value 值
* @param int $timeOut 時間 0表示無過期時間
* @return
*/
public function sAdd($key, $value, $timeOut = 0)
{
$re = $this->redisObj[$this->sn]->sadd($key, $value);
if ($timeOut > 0) $this->redisObj[$this->sn]->expire($key, $timeOut);
return $re;
}
/**
* 查,取集合對應元素
* @param string $key 集合名字
*/
public function sMembers($key)
{
$re = $this->redisObj[$this->sn]->exists($key);//存在返回1,不存在返回0
if (!$re) return false;
return $this->redisObj[$this->sn]->smembers($key);
}
/*------------------------------------3.end set結構----------------------------------------------------*/
/*------------------------------------4.start sort set結構----------------------------------------------------*/
/*
* 增,改,構建一個集合(有序集合),支持批量寫入,更新
* @param string $key 集合名稱
* @param array $score_value key為scoll, value為該權的值
* @return int 插入操作成功返回插入數量【,更新操作返回0】
*/
public function zadd($key, $score_value, $timeOut = 0)
{
if (!is_array($score_value)) return false;
$a = 0;//存放插入的數量
foreach ($score_value as $score => $value) {
$re = $this->redisObj[$this->sn]->zadd($key, $score, $value);//當修改時,可以修改,但不返回更新數量
$re && $a += 1;
if ($timeOut > 0) $this->redisObj[$this->sn]->expire($key, $timeOut);
}
return $a;
}
/**
* 查,有序集合查詢,可升序降序,默認從第一條開始,查詢一條數據
* @param $key ,查詢的鍵值
* @param $min ,從第$min條開始
* @param $max,查詢的條數
* @param $order ,asc表示升序排序,desc表示降序排序
* @return array|bool 如果成功,返回查詢信息,如果失敗返回false
*/
public function zRange($key, $min = 0, $num = 1, $order = 'desc')
{
$re = $this->redisObj[$this->sn]->exists($key);//存在返回1,不存在返回0
if (!$re) return false;//不存在鍵值
if ('desc' == strtolower($order)) {
$re = $this->redisObj[$this->sn]->zrevrange($key, $min, $min + $num - 1);
} else {
$re = $this->redisObj[$this->sn]->zrange($key, $min, $min + $num - 1);
}
if (!$re) return false;//查詢的范圍值為空
return $re;
}
/**
* 返回集合key中,成員member的排名
* @param $key,鍵值
* @param $member,scroll值
* @param $type ,是順序查找還是逆序
* @return bool,鍵值不存在返回false,存在返回其排名下標
*/
public function zrank($key, $member, $type = 'desc')
{
$type = strtolower(trim($type));
if ($type == 'desc') {
$re = $this->redisObj[$this->sn]->zrevrank($key, $member);//其中有序集成員按score值遞減(從大到小)順序排列,返回其排位
} else {
$re = $this->redisObj[$this->sn]->zrank($key, $member);//其中有序集成員按score值遞增(從小到大)順序排列,返回其排位
}
if (!is_numeric($re)) return false;//不存在鍵值
return $re;
}
/**
* 返回名稱為key的zset中score >= star且score <= end的所有元素
* @param $key
* @param $member
* @param $star,
* @param $end ,
* @return array
*/
public function zrangbyscore($key, $star, $end)
{
return $this->redisObj[$this->sn]->ZRANGEBYSCORE($key, $star, $end);
}
/**
* 返回名稱為key的zset中元素member的score
* @param $key
* @param $member
* @return string ,返回查詢的member值
*/
function zScore($key, $member)
{
return $this->redisObj[$this->sn]->ZSCORE($key, $member);
}
/*------------------------------------4.end sort set結構----------------------------------------------------*/
/*------------------------------------5.hash結構----------------------------------------------------*/
public function hSetJson($redis_key, $field, $data, $timeOut = 0)
{
$redis_info = json_encode($data); //field的數據value,以json的形式存儲
$re = $this->redisObj[$this->sn]->hSet($redis_key, $field, $redis_info);//存入緩存
if ($timeOut > 0) $this->redisObj[$this->sn]->expire($redis_key, $timeOut);//設置過期時間
return $re;
}
public function hGetJson($redis_key, $field)
{
$info = $this->redisObj[$this->sn]->hget($redis_key, $field);
if ($info) {
$info = json_decode($info, true);
} else {
$info = false;
}
return $info;
}
public function hSet($redis_key, $name, $data, $timeOut = 0)
{
$re = $this->redisObj[$this->sn]->hset($redis_key, $name, $data);
if ($timeOut > 0) $this->redisObj[$this->sn]->expire($redis_key, $timeOut);
return $re;
}
public function hSetNx($redis_key, $name, $data, $timeOut = 0)
{
$re = $this->redisObj[$this->sn]->hsetNx($redis_key, $name, $data);
if ($timeOut > 0) $this->redisObj[$this->sn]->expire($redis_key, $timeOut);
return $re;
}
/**
* 增,普通邏輯的插入hash數據類型的值
* @param $key ,鍵名
* @param $data |array 一維數組,要存儲的數據
* @param $timeOut |num 過期時間
* @return $number 返回OK【更新和插入操作都返回ok】
*/
public function hMset($key, $data, $timeOut = 0)
{
$re = $this->redisObj[$this->sn]->hmset($key, $data);
if ($timeOut > 0) $this->redisObj[$this->sn]->expire($key, $timeOut);
return $re;
}
/**
* 查,普通的獲取值
* @param $key ,表示該hash的下標值
* @return array 。成功返回查詢的數組信息,不存在信息返回false
*/
public function hVals($key)
{
$re = $this->redisObj[$this->sn]->exists($key);//存在返回1,不存在返回0
if (!$re) return false;
$vals = $this->redisObj[$this->sn]->hvals($key);
$keys = $this->redisObj[$this->sn]->hkeys($key);
$re = array_combine($keys, $vals);
foreach ($re as $k => $v) {
if (!is_null(json_decode($v))) {
$re[$k] = json_decode($v, true);//true表示把json返回成數組
}
}
return $re;
}
/**
*
* @param $key
* @param $filed
* @return bool|string
*/
public function hGet($key, $filed = [])
{
if (empty($filed)) {
$re = $this->redisObj[$this->sn]->hgetAll($key);
} elseif (is_string($filed)) {
$re = $this->redisObj[$this->sn]->hget($key, $filed);
} elseif (is_array($filed)) {
$re = $this->redisObj[$this->sn]->hMget($key, $filed);
}
if (!$re) {
return false;
}
return $re;
}
public function hDel($redis_key, $name)
{
$re = $this->redisObj[$this->sn]->hdel($redis_key, $name);
return $re;
}
public function hLan($redis_key)
{
$re = $this->redisObj[$this->sn]->hLen($redis_key);
return $re;
}
public function hIncre($redis_key, $filed, $value = 1)
{
return $this->redisObj[$this->sn]->hIncrBy($redis_key, $filed, $value);
}
/**
* 檢驗某個鍵值是否存在
* @param $keys keys
* @param string $type 類型,默認為常規
* @param string $field 若為hash類型,輸入$field
* @return bool
*/
public function hExists($keys, $field = '')
{
$re = $this->redisObj[$this->sn]->hexists($keys, $field);//有返回1,無返回0
return $re;
}
/*------------------------------------end hash結構----------------------------------------------------*/
/*------------------------------------其他結構----------------------------------------------------*/
/**
* 設置自增,自減功能
* @param $key ,要改變的鍵值
* @param int $num ,改變的幅度,默認為1
* @param string $member ,類型是zset或hash,需要在輸入member或filed字段
* @param string $type,類型,default為普通增減 ,還有:zset,hash
* @return bool|int 成功返回自增后的scroll整數,失敗返回false
*/
public function incre($key, $num = 1, $member = '', $type = '')
{
$num = intval($num);
switch (strtolower(trim($type))) {
case "zset":
$re = $this->redisObj[$this->sn]->zIncrBy($key, $num, $member);//增長權值
break;
case "hash":
$re = $this->redisObj[$this->sn]->hincrby($key, $member, $num);//增長hashmap里的值
break;
default:
if ($num > 0) {
$re = $this->redisObj[$this->sn]->incrby($key, $num);//默認增長
} else {
$re = $this->redisObj[$this->sn]->decrBy($key, -$num);//默認增長
}
break;
}
if ($re) return $re;
return false;
}
/**
* 清除緩存
* @param int $type 默認為0,清除當前數據庫;1表示清除所有緩存
*/
function flush($type = 0)
{
if ($type) {
$this->redisObj[$this->sn]->flushAll();//清除所有數據庫
} else {
$this->redisObj[$this->sn]->flushdb();//清除當前數據庫
}
}
/**
* 檢驗某個鍵值是否存在
* @param $keys keys
* @param string $type 類型,默認為常規
* @param string $field 若為hash類型,輸入$field
* @return bool
*/
public function exists($keys, $type = '', $field = '')
{
switch (strtolower(trim($type))) {
case 'hash':
$re = $this->redisObj[$this->sn]->hexists($keys, $field);//有返回1,無返回0
break;
default:
$re = $this->redisObj[$this->sn]->exists($keys);
break;
}
return $re;
}
/**
* 刪除緩存
* @param string|array $key 鍵值
* @param $type 類型 默認為常規,還有hash,zset
* @param string $field ,hash=>表示$field值,set=>表示value,zset=>表示value值,list類型特殊暫時不加
* @return int | 返回刪除的個數
*/
public function delete($key, $type = "default", $field = '')
{
switch (strtolower(trim($type))) {
case 'hash':
$re = $this->redisObj[$this->sn]->hDel($key, $field);//返回刪除個數
break;
case 'set':
$re = $this->redisObj[$this->sn]->sRem($key, $field);//返回刪除個數
break;
case 'zset':
$re = $this->redisObj[$this->sn]->zDelete($key, $field);//返回刪除個數
break;
default:
$re = $this->redisObj[$this->sn]->del($key);//返回刪除個數
break;
}
return $re;
}
//日志記錄
public function logger($log_content, $position = 'user')
{
$max_size = 1000000; //聲明日志的最大尺寸1000K
$log_dir = './log';//日志存放根目錄
if (!file_exists($log_dir)) mkdir($log_dir, 0777);//如果不存在該文件夾,創建
if ($position == 'user') {
$log_filename = "{$log_dir}/User_redis_log.txt"; //日志名稱
} else {
$log_filename = "{$log_dir}/Wap_redis_log.txt"; //日志名稱
}
//如果文件存在并且大于了規定的最大尺寸就刪除了
if (file_exists($log_filename) && (abs(filesize($log_filename)) > $max_size)) {
unlink($log_filename);
}
//寫入日志,內容前加上時間, 后面加上換行, 以追加的方式寫入
file_put_contents($log_filename, date('Y-m-d_H:i:s') . " " . $log_content . "\n", FILE_APPEND);
}
function flushDB()
{
$this->redisObj[$this->sn]->flushDB();
}
function __destruct()
{
$this->redisObj[$this->sn]->close();
}
/**
* 魔術方法 有不存在的操作的時候執行
* @access public
* @param string $method 方法名
* @param array $args 參數
* @return mixed
*/
public function __call($method, $args)
{
call_user_func_array([$this->redisObj[$this->sn], $method], $args);
}
}
~~~
本來想實現的是隊列發消息記錄日志,發送郵件通知的,結果發現sentry自帶異步通知機制,所以先保存下來。
- PHP7新特性
- 優雅的寫代碼
- 常見的代碼優化
- 常用的工具類
- PHP原生生成EXCEL
- PHP地理位置計算
- PHP獲取服務器狀態
- 駝峰轉下劃線
- 百度地圖兩點坐標距離計算
- 判斷是否是url
- PHP常見header頭
- 郵件發送類
- 阿拉伯數字轉化為大寫
- 獲取漢字首個拼音
- 根據身份證號獲取星座
- 生成驗證碼類
- 生成唯一ID
- 身份證驗證類
- PHP中文轉拼音
- Nginx配置文件
- curl獲取網頁內容
- 快遞查詢api
- 上傳圖片類
- 股票類
- 找回密碼類
- 字符串助手函數
- 校驗數據規則
- PHP獲取收集相關信息
- 字符串截取助手函數
- 網頁中提取關鍵字
- 檢測瀏覽器語言
- 微信相關類
- 微信獲取access_token
- 獲取用戶基本信息
- 代碼規范
- 編程規范(psr-1,2)
- 編程規范(原作者的建議)
- 經驗
- 常用函數地址
- 函數集合
- 一些常識
- MYSQL相關知識
- 常用sql
- mysql事務隔離級別
- Read uncommitted
- Read committed
- Repeatable read
- Serializable
- 高性能MYSQL讀書筆記
- 第一章MYSQL的架構
- mysql邏輯架構
- redis相關知識
- 1.安裝redis
- 3.php操作redis
- 隊列
- 悲觀鎖
- 樂觀鎖
- 發布
- 訂閱
- redis實戰-文章投票
- 設計模式
- 創建模型實例
- 單例模式
- 工廠模式
- AnimalInterface.php
- Chicken.php
- Factory.php
- Farm.php
- Pig
- SampleFactory.php
- Zoo
- 抽象工廠模式
- AnimalFactory
- Factory
- FarmInterface
- Income
- PandaZoo
- PeonyZoo
- PigFarm
- PlantFactory
- RiceFarm
- ZooInterface
- 原型模式
- 建造者模式
- 結構型模式實例
- 橋接模式
- 享元模式
- 外觀模式
- 適配器模式
- 裝飾器模式
- 組合模式
- 代理模式哦
- 過濾器模式
- 行為型模式實例
- 模板模式
- 策略模式
- 狀態模式
- 觀察者模式
- 責任鏈模式
- 訪問者模式
- 解釋器模式
- 空對象模式
- 中介者模式
- 迭代器模式
- 命令模式
- 備忘錄模式
- 網絡知識
- 互聯網協議概述
- nginx簡易交互過程
- HTTP知識
- LINUX相關知識
- swoole學習
- 1.初識swoole
- 2.WebSocket PHP 即時通訊開發
- 3.異步多進程的 CURL
- 4.異步非阻塞多進程的 Http 服務器
- 5.TCP 服務器
- 5.1同步 TCP 客戶端
- 5.2異步 TCP 客戶端
- 6.UDP 服務器
- 7.異步多任務處理
- 8.毫秒定時器
- 9.高并發投票
- ThinkPHP5學習
- 命令行操作
- 所有命令行中用到的基類
- 1.base
- 2.WorkerBase
- 3.TimeWorkerBase
- 4.CycleWorkerBase
- 5.WorkerCommandBase
- 6.WorkerHookBase
- 1.基礎命令實現
- 2.建立Linux上的守護源碼
- 3.發送模板消息
- 4.基于命令行實現自己的隊列模式
- 5.發送定時短信
- thinkphp5使用sentry
- sentry通知,記錄日志
- 高級查詢
- Kafka相關
- 1.安裝
- 2.為php打擴展
- 3.kafka實現
- 一些工具搭建
- sentry日志收集系統搭建
- walle搭建
- php實現定時任務
- 檢測文件變化