<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # == 和 = 的問題 在連續判斷中,如果我們把== 誤寫成 = 會帶來很嚴重的后果。 如 if($a== 'a'){ } if($a= 'c'){ //一次誤寫,就影響后續的變化 } if($a == 'c'){ } 結果方法 : 比較值放前面 if('a' == $a) # sqlite date類型查詢的問題 朋友有個表 ![](https://box.kancloud.cn/2016-02-29_56d3b60caa555.png) 開始 想查大于 1992-07-01的數據 按照原始的方法 HireDate > '1992-07-01'發現只查出 1993年的了 后來找了半天 最簡單方法是 `select * from Mytable where HireDate >= '1/7/1992'` 按照他顯示的格式查 當字符串去比較 # 數據庫對比 介紹 本章主要介紹怎樣對比數據庫的表結構的差異,這里主要介紹使用mysqldiff工具來對比表結構的差異,其實在5.6版本之后通過查詢information庫中的系統表也能對比出來,但是mysqldiff還有一個好處就是可以直接生產差異的SQL語句這個功能就是我們需要利用的,而通過分析系統表要實現這個就比較難;接下來就來看看怎樣使用這個工具。 語法 `mysqldiff --server1=user:pass@host:port:socket --server2=user:pass@host:port:socket db1.object1:db2.object1 db3:db4` 這個語法有兩個用法: db1:db2:如果只是指定數據庫,那么就將兩個數據庫中互相缺少的對象顯示出來,而對象里面的差異不進行對比;這里的對象包括表、存儲過程、函數、觸發器等。 db1.object1:db2.object1:如果指定了具體表對象,那么就會詳細對比兩個表的差異,包括表名、字段名、備注、索引、大小寫等都有的表相關的對象。 接下來看一些主要的參數: ~~~ --server1:配置server1的連接 --server2:配置server2的連接 --character-set:配置連接時用的字符集,如果不顯示配置默認使用“character_set_client” --width:配置顯示的寬度 --skip-table-options:這個選項的意思是保持表的選項不變,即對比的差異里面不包括表名、AUTO_INCREMENT,ENGINE, CHARSET等差異。 -d DIFFTYPE, --difftype:差異的信息顯示的方式,有[unified|context|differ|sql](default: unified),如果使用sql那么就直接生成差異的SQL這樣非常方便。 --changes-for=:例如--changes-for=server2,那么對比以sever1為主,生成的差異的修改也是針對server2的對象的修改。 --show-reverse:這個字面意思是顯示相反的意思,其實是生成的差異修改里面同時會包含server2和server1的修改。 ~~~ 測試 ~~~ use study; create table test1 (id int not null primary key, a varchar(10) not null, b varchar(10), c varchar(10) comment 'c', d int ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='test1'; create table test2 (id int not null , a varchar(10), b varchar(5), c varchar(10), D int ) ENGINE=myisam DEFAULT CHARSET=utf8 COMMENT='test2'; ~~~ 1.不使用--skip-table-options `mysqldiff --server1=root:root@localhost --server2=root:root@localhost --changes-for=server2 --show-reverse --difftype=sql study.test1:study.test2` ![](https://box.kancloud.cn/5d8a2e8331cd74dee22384895dc81cca_1610x643.png) 2.使用--skip-table-options ![](https://box.kancloud.cn/580b5c676dee70e986f187ec298d6598_1786x595.png) 其實用SQL語句也可以達到查詢的效果,這里就貼上平時用的對比語句。 ~~~ ############################################################################################################################### ##判斷兩個數據庫相同表的字段不為空是否相同 select a.TABLE_SCHEMA,a.TABLE_NAME,a.COLUMN_NAME,a.COLUMN_TYPE,a.IS_NULLABLE,a.COLUMN_DEFAULT,b.TABLE_SCHEMA,b.TABLE_NAME,b.COLUMN_NAME,b.COLUMN_TYPE,b.IS_NULLABLE ,b.COLUMN_DEFAULT,b.COLUMN_COMMENT from information_schema.`COLUMNS` a inner join information_schema.`COLUMNS` b on a.TABLE_SCHEMA='db1' and b.TABLE_SCHEMA='db2'and a.TABLE_NAME=b.TABLE_NAME and a.COLUMN_NAME=b.COLUMN_NAME and a.IS_NULLABLE<>b.IS_NULLABLE where a.IS_NULLABLE='NO'; ################################################################################################################################ ##判斷兩個數據庫相同表的字段默認值是否相同 select a.TABLE_SCHEMA,a.TABLE_NAME,a.COLUMN_NAME,a.COLUMN_DEFAULT,b.TABLE_SCHEMA,b.TABLE_NAME,b.COLUMN_NAME,b.COLUMN_DEFAULT from information_schema.`COLUMNS` a inner join information_schema.`COLUMNS` b on a.TABLE_SCHEMA='db1' and b.TABLE_SCHEMA='db2' and a.TABLE_NAME=b.TABLE_NAME and a.COLUMN_NAME=b.COLUMN_NAME and a.COLUMN_DEFAULT<>b.COLUMN_DEFAULT; ################################################################################################################################# ##判斷兩個數據庫相同表的字段數據類型是否相同,這里是判斷數據類型不同如果要判斷數據類型的長度不同需要用COLUMN_TYPE字段 select a.TABLE_SCHEMA,a.TABLE_NAME,a.COLUMN_NAME,a.DATA_TYPE,a.COLUMN_DEFAULT,b.TABLE_SCHEMA,b.TABLE_NAME,b.COLUMN_NAME,b.DATA_TYPE ,b.COLUMN_DEFAULT from information_schema.`COLUMNS` a inner join information_schema.`COLUMNS` b on a.TABLE_SCHEMA='db1' and b.TABLE_SCHEMA='db2' and a.TABLE_NAME=b.TABLE_NAME and a.COLUMN_NAME=b.COLUMN_NAME and a.DATA_TYPE<>b.DATA_TYPE; ################################################################################################################################## ##判斷兩個數據庫相同表的中互相不存在的字段 select a.TABLE_SCHEMA,a.TABLE_NAME,a.COLUMN_NAME,a.DATA_TYPE,a.COLUMN_DEFAULT from information_schema.`COLUMNS` a where a.TABLE_SCHEMA='db1' and a.COLUMN_NAME NOT IN(SELECT b.COLUMN_NAME from information_schema.`COLUMNS` b where b.TABLE_SCHEMA='db2' and a.TABLE_SCHEMA='db1' and a.TABLE_NAME=b.TABLE_NAME ); select a.TABLE_SCHEMA,a.TABLE_NAME,a.COLUMN_NAME,a.DATA_TYPE,a.COLUMN_DEFAULT from information_schema.`COLUMNS` a where a.TABLE_SCHEMA='db2' and a.COLUMN_NAME NOT IN(SELECT b.COLUMN_NAME from information_schema.`COLUMNS` b where b.TABLE_SCHEMA='db1' and a.TABLE_SCHEMA='db2' and a.TABLE_NAME=b.TABLE_NAME ); ####mysql沒有full jion所以變相的多做了一次select查詢,這種方法性能比較差,對于表比較多的數據庫建議使用上面的分開查詢 select b.TABLE_SCHEMA,b.TABLE_NAME,b.COLUMN_NAME,b.DATA_TYPE,c.TABLE_SCHEMA,c.TABLE_NAME,c.COLUMN_NAME,c.DATA_TYPE from (select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,DATA_TYPE from information_schema.`COLUMNS` a where a.TABLE_SCHEMA in('db2','db1') )a left join (select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,DATA_TYPE from information_schema.`COLUMNS` a where a.TABLE_SCHEMA in('db2')) b on a.TABLE_NAME=b.TABLE_NAME AND a.COLUMN_NAME=b.COLUMN_NAME left join (select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,DATA_TYPE from information_schema.`COLUMNS` a where a.TABLE_SCHEMA in('db1')) c on a.TABLE_NAME=c.TABLE_NAME AND a.COLUMN_NAME=c.COLUMN_NAME where b.COLUMN_NAME is null or c.COLUMN_NAME is null ; ####################################################################################################################### ##判斷兩個數據庫互相不存在的表 select a.TABLE_SCHEMA,a.TABLE_NAME from information_schema.TABLES a where a.TABLE_SCHEMA='db1' and a.TABLE_NAME NOT IN(SELECT b.TABLE_NAME from information_schema.TABLES b where b.TABLE_SCHEMA='db2'); select a.TABLE_SCHEMA,a.TABLE_NAME from information_schema.TABLES a where a.TABLE_SCHEMA='db2' and a.TABLE_NAME NOT IN(SELECT b.TABLE_NAME from information_schema.TABLES b where b.TABLE_SCHEMA='db1'); select b.TABLE_SCHEMA,b.TABLE_NAME,c.TABLE_SCHEMA,c.TABLE_NAME from (select TABLE_SCHEMA,TABLE_NAME from information_schema.TABLES a where a.TABLE_SCHEMA in('db2','db1') )a left join (select TABLE_SCHEMA,TABLE_NAME from information_schema.TABLES a where a.TABLE_SCHEMA in('db2')) b on a.TABLE_NAME=b.TABLE_NAME left join (select TABLE_SCHEMA,TABLE_NAME from information_schema.TABLES a where a.TABLE_SCHEMA in('db1')) c on a.TABLE_NAME=c.TABLE_NAME where b.TABLE_NAME is null or c.TABLE_NAME is null ; ~~~ 總結 這里沒有演示對數據庫的對比,數據庫的對比顯示的只是缺少的數據庫對象,理解起來更加容易。 備注: 作者:pursuer.chen 博客:http://www.cnblogs.com/chenmh 本站點所有隨筆都是原創,歡迎大家轉載;但轉載時必須注明文章來源,且在文章開頭明顯處給明鏈接。 # rtrim的問題 rtrim 是把trim 的字符串拆分開來 去匹配 因此 rtrim('3%3b', '%3b') 會連 3一塊過濾了,什么都不留了。 # mysql數據精度問題 1.float類型 float列類型默認長度查不到結果,必須指定精度,比如? num float, insert into table (num) values (0.12); select * from table where num=0.12的話,empty set。 num float(9,7), insert into table (num) values (0.12); select * from table where num=0.12的話會查到這條記錄。 mysql> create table tt ??? -> ( ??? -> num float(9,3) ??? -> ); Query OK, 0 rows affected (0.03 sec) mysql> insert into tt(num)values(1234567.8); Query OK, 1 row affected, 1 warning (0.04 sec) 注:超出字段范圍,插入數據有誤 mysql> select * from tt; +-------------+ | num???????? | +-------------+ | 1000000.000 | +-------------+ 2 rows in set (0.00 sec) *************************************************************************** 注:通常在 linux 下安裝完 mysql 后,默認的 sql-mode 值是空,在這種情形下 mysql 執行的是一種不嚴格的檢查,例如日期字段可以插入 ’ 0000-00-00 00:00:00 ’這樣的值,還有如果要插入的字段長度超過列定義的長度,那么 mysql 不會終止操作,而是會自動截斷后面的字符繼續插入操作。 我們發現插入的字符被自動截斷了,但是如果我們本意希望如果長度超過限制就報錯,那么我們可以設置 sql_mode 為 STRICT_TRANS_TABLES ,如下: mysql> set session sql_mode='STRICT_TRANS_TABLES'; 這樣我們再執行同樣的操作,mysql 就會告訴我們插入的值太長,操作被終止,如下: mysql> insert into tt(num) values(1234567.8); ERROR 1264 (22003): Out of range value for column 'num' at row 1 *************************************************************************** mysql> insert into tt(num)values(123456.8); Query OK, 1 row affected (0.00 sec) mysql> select * from tt; +-------------+ | num???????? | +-------------+ | 1000000.000 | |? 123456.797 | +-------------+ 2 rows in set (0.00 sec) 注:小數位數不夠,自動補齊,但是存在一個問題就是如上的近似值。 mysql> insert into tt(num)values(123456.867); Query OK, 1 row affected (0.04 sec) mysql> select * from tt; +-------------+ | num???????? | +-------------+ | 1000000.000 | |? 123456.797 | |? 123456.867 | +-------------+ 3 rows in set (0.00 sec) mysql> select * from tt where num=123456.867; +------------+ | num??????? | +------------+ | 123456.867 | +------------+ 1 row in set (0.00 sec) mysql> insert into tt(num)values(2.8); Query OK, 1 row affected (0.04 sec) mysql> select * from tt; +-------------+ | num???????? | +-------------+ | 1000000.000 | |? 123456.797 | |? 123456.867 | |?????? 2.800 | +-------------+ 4 rows in set (0.00 sec) mysql> select * from tt where num=2.8; +-------+ | num?? | +-------+ | 2.800 | +-------+ 1 row in set (0.00 sec) mysql> insert into tt(num)values(2.888888); Query OK, 1 row affected (0.00 sec) mysql> select * from tt; +-------------+ | num???????? | +-------------+ | 1000000.000 | |? 123456.797 | |? 123456.867 | |?????? 2.800 | |?????? 2.889 | +-------------+ 5 rows in set (0.00 sec) 注:小數位數超了,自動取近似值。 -------------------------------------------------------------------------------------- 2.double類型 mysql> create table tt( ??? -> num double(9,3) ??? -> ); Query OK, 0 rows affected (0.04 sec) mysql> insert into tt(num) values(234563.9); Query OK, 1 row affected (0.00 sec) mysql> select * from tt; +------------+ | num??????? | +------------+ | 234563.900 | +------------+ 1 row in set (0.00 sec) mysql> insert into tt(num) values(2345623.2); Query OK, 1 row affected, 1 warning (0.04 sec) mysql> insert into tt(num) values(234563.2); Query OK, 1 row affected (0.00 sec) mysql> select * from tt; +------------+ | num??????? | +------------+ | 234563.900 | | 999999.999 | | 234563.200 | +------------+ 2 rows in set (0.00 sec) mysql> insert into tt(num) values(2.8); Query OK, 1 row affected (0.00 sec) mysql> select * from tt; +------------+ | num??????? | +------------+ | 234563.900 | | 999999.999 | | 234563.200 | |????? 2.800 | +------------+ 3 rows in set (0.00 sec) FLOAT(M,D)或REAL(M,D)或DOUBLE PRECISION(M,D)。這里,“(M,D)”表示該值一共顯示M位整數,其中D位位于小數點后面。 例如,定義為FLOAT(7,4)的一個列可以顯示為-999.9999。MySQL保存值時進行四舍五入,因此如果在FLOAT(7,4)列內插入999.00009,近似結果是999.0001。 單精度浮點數(float)的尾數是用24bit表示的,雙精度(double)浮點數的尾數是用53bit表示的,轉換成十進制: 2^24 - 1 = 16777215????????? ? 2^53 - 1 = 9007199254740991??? ? 由上可見,IEEE754單精度浮點數的有效數字二進制是24位,按十進制來說,是8位;雙精度浮點數的有效數字二進制是53位,按十進制來說,是16 位。 # swoole+inotify實現異步實時文件監控 ## inotify擴展介紹 inotify是Linux內核提供的一組系統調用,它可以監控文件系統操作,比如文件或者目錄的創建、讀取、寫入、權限修改和刪除等。 inotify使用也很簡單,使用inotify_init創建一個句柄,然后通過inotify_add_watch/inotify_rm_watch增加/刪除對文件和目錄的監聽。 PHP中提供了inotify擴展,支持了inotify系統調用。inotify本身也是一個文件描述符,可以加入到事件循環中,配合使用swoole擴展,就可以異步非阻塞地實時監聽文件/目錄變化。 ## 安裝inotify/swoole擴展 如果已經安裝了inotify/swoole可以跳過此步驟。 ~~~ pecl?install?swoole pecl?install?inotify ~~~ 操作成功后,修改php.ini,加入 ~~~ extension=swoole.so extension=inotify.so ~~~ 查看擴展是否加載成功: ~~~ php?-m?|?grep?swoole php?-m?|?grep?inotify ~~~ ## inotify的使用 首先在當前目錄創建一個inotify.data文件,示例就用來監聽此文件。 ~~~ //創建一個inotify句柄 $fd?=?inotify_init(); //監聽文件,僅監聽修改操作,如果想要監聽所有事件可以使用IN_ALL_EVENTS $watch_descriptor?=?inotify_add_watch($fd,?__DIR__.'/inotify.data',?IN_MODIFY);? while?(true)?{ ????//阻塞地讀取數據 ????$events?=?inotify_read($fd); ????if?($events)?{ ????????foreach?($events?as?$event)?{ ????????????echo?"inotify?Event?:".var_export($event,?1)."\n"; ????????} ????} } //釋放inotify句柄 inotify_rm_watch($fd,?$watch_descriptor); fclose($fd); ~~~ 修改inotify.data,就可以看到程序輸出了信息。 ~~~ echo?"hello?world"?>?inotify.data inotify?Event?:array?( ??'wd'?=>?1, ??'mask'?=>?2, ??'cookie'?=>?0, ??'name'?=>?'', ) ~~~ ## swoole+inotify異步非阻塞監聽文件 ~~~ //創建一個inotify句柄 $fd?=?inotify_init(); //監聽文件,僅監聽修改操作,如果想要監聽所有事件可以使用IN_ALL_EVENTS $watch_descriptor?=?inotify_add_watch($fd,?__DIR__.'/inotify.data',?IN_MODIFY); //加入到swoole的事件循環中 swoole_event_add($fd,?function?($fd)?{ ????$events?=?inotify_read($fd); ????if?($events)?{ ????????foreach?($events?as?$event)?{ ????????????echo?"inotify?Event?:"?.?var_export($event,?1)?.?"\n"; ????????} ????} }); ~~~ 這里使用了swoole擴展提供swoole_event_add函數,將inotify句柄設置為非阻塞,并加入到epoll事件循環中。程序變成異步非阻塞模式。當有事件發生時才會執行inotify_read獲取事件。沒有事件發生時,程序可以執行其他的邏輯。 此程序與上一個同步阻塞例子的邏輯是相同的,向inotify寫入內容時也會打印事件信息。區別在于swoole+inotify的程序是異步的。可以支持并發監聽大量文件和目錄,并且除了inotify操作之外還可以執行其他的IO操作。 * 關于inotify更多的信息可以到PHP官方網站中查看?[http://php.net/inotify](http://php.net/inotify) * 關于swoole更多信息,請到swoole官方網站取了解?[http://www.swoole.com/](http://www.swoole.com/)?? ~~~ [sql] -- ---------------------------- -- Table structure for oxygen_activity -- ---------------------------- DROP TABLE IF EXISTS `oxygen_activity`; CREATE TABLE `oxygen_activity` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL DEFAULT '' COMMENT '名稱', `start_time` datetime DEFAULT NULL COMMENT '開始時間', `end_time` datetime DEFAULT NULL COMMENT '結束時間', `sort` int(11) unsigned DEFAULT '0' COMMENT '排序 小在前面', `status` tinyint(1) unsigned DEFAULT '1' COMMENT '1-開啟 0-結束', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='活動表'; -- ---------------------------- -- Table structure for oxygen_activity_detail -- ---------------------------- DROP TABLE IF EXISTS `oxygen_activity_detail`; CREATE TABLE `oxygen_activity_detail` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `oxygen_activity_id` int(11) unsigned DEFAULT '0' COMMENT '活動id', `product_id` int(11) unsigned DEFAULT NULL COMMENT '產品id', `present` tinyint(1) unsigned DEFAULT '0' COMMENT '贈送 1-是 0-否', `discount` float(3,2) unsigned DEFAULT '1.00' COMMENT '折扣 1.00 ', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='活動明細表'; -- ---------------------------- -- Table structure for oxygen_balance -- ---------------------------- DROP TABLE IF EXISTS `oxygen_balance`; CREATE TABLE `oxygen_balance` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(64) DEFAULT '' COMMENT '標題', `money` float(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '金額', `type` enum('收入','支出') DEFAULT '支出' COMMENT '類型', `uid` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用戶uid', `order_id` int(11) unsigned DEFAULT '0' COMMENT '關聯訂單id', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='收支表'; -- ---------------------------- -- Table structure for oxygen_comment -- ---------------------------- DROP TABLE IF EXISTS `oxygen_comment`; CREATE TABLE `oxygen_comment` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `order_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '訂單id', `content` text COMMENT '內容', `uid` bigint(20) unsigned DEFAULT '0' COMMENT '用戶uid', `leased_poin_uid` bigint(20) unsigned DEFAULT '0' COMMENT '租賃點uid', `leased_poin_score` tinyint(1) unsigned DEFAULT '0' COMMENT '租賃點評分1-5分', `leased_point_server_uid` bigint(20) unsigned DEFAULT '0' COMMENT '租賃點服務員uid', `leased_point_server_score` tinyint(1) unsigned DEFAULT '0' COMMENT '租賃點服務員評分1-5分', `return_point_uid` bigint(20) unsigned DEFAULT '0' COMMENT '歸還租賃點uid', `return_point_score` tinyint(1) unsigned DEFAULT '0' COMMENT '歸還點拼分1-5分', `return_point_server_uid` bigint(20) unsigned DEFAULT '0' COMMENT '歸還點 服務員uid', `return_point_server_score` tinyint(1) unsigned DEFAULT '0' COMMENT '歸還點服務員評分', `device_score` tinyint(1) unsigned DEFAULT '0' COMMENT '設備評分', `device_id` int(11) unsigned DEFAULT '0' COMMENT '設備id', `remark` varchar(10000) DEFAULT '' COMMENT '備注', `create_time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='評論表'; -- ---------------------------- -- Table structure for oxygen_compensate -- ---------------------------- DROP TABLE IF EXISTS `oxygen_compensate`; CREATE TABLE `oxygen_compensate` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `product_id` int(11) unsigned DEFAULT '0' COMMENT '產品id', `position` varchar(64) NOT NULL DEFAULT '' COMMENT '賠償部位', `price` float(10,2) unsigned DEFAULT '0.00' COMMENT '價格', `sort` int(11) unsigned DEFAULT '0' COMMENT '排序', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='賠償表'; -- ---------------------------- -- Table structure for oxygen_device -- ---------------------------- DROP TABLE IF EXISTS `oxygen_device`; CREATE TABLE `oxygen_device` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `sn` varchar(11) DEFAULT '' COMMENT 'sn', `bind_uid` int(11) unsigned DEFAULT '0' COMMENT '綁定uid', `bind_time` datetime DEFAULT NULL COMMENT '綁定時間', `status` enum('激活','已綁定','租賃中','異常','丟失') DEFAULT '激活' COMMENT '狀態', `create_time` datetime DEFAULT NULL COMMENT '激活時間', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='設備表'; -- ---------------------------- -- Table structure for oxygen_exchange -- ---------------------------- DROP TABLE IF EXISTS `oxygen_exchange`; CREATE TABLE `oxygen_exchange` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `order_id` int(11) unsigned DEFAULT '0' COMMENT '訂單id', `from_device_id` int(11) unsigned DEFAULT '0' COMMENT '來源設備id', `to_device_id` int(11) unsigned DEFAULT '0' COMMENT '更換設備id', `create_time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='換貨單'; -- ---------------------------- -- Table structure for oxygen_leasehold_class -- ---------------------------- DROP TABLE IF EXISTS `oxygen_leasehold_class`; CREATE TABLE `oxygen_leasehold_class` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(32) NOT NULL DEFAULT '' COMMENT '32', `sort` int(11) unsigned DEFAULT '0' COMMENT '排序', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='租賃點分類'; -- ---------------------------- -- Table structure for oxygen_leasehold_level -- ---------------------------- DROP TABLE IF EXISTS `oxygen_leasehold_level`; CREATE TABLE `oxygen_leasehold_level` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(32) NOT NULL DEFAULT '' COMMENT '名稱', `rate` float(4,3) unsigned NOT NULL DEFAULT '0.050' COMMENT '提成比例', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='租賃點級別'; -- ---------------------------- -- Table structure for oxygen_message -- ---------------------------- DROP TABLE IF EXISTS `oxygen_message`; CREATE TABLE `oxygen_message` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `uid` int(11) unsigned DEFAULT '0' COMMENT '收到人uid', `content` text COMMENT '內容', `create_time` datetime DEFAULT NULL COMMENT '新增時間', `type` enum('業務員','租賃點','服務員','公眾號') DEFAULT '業務員' COMMENT '類型', `status` enum('未讀','已讀','已刪除') DEFAULT '未讀' COMMENT '狀態', `read_time` datetime DEFAULT NULL COMMENT '閱讀時間', `data_type` varchar(0) DEFAULT '' COMMENT '數據類型', `data_id` int(11) unsigned DEFAULT '0' COMMENT '關聯id', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='消息表'; -- ---------------------------- -- Table structure for oxygen_order -- ---------------------------- DROP TABLE IF EXISTS `oxygen_order`; CREATE TABLE `oxygen_order` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `no` char(14) NOT NULL DEFAULT '' COMMENT '訂單編號', `uid` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用戶uid', `create_time` datetime DEFAULT NULL COMMENT '創建時間', `type` enum('普通單','換貨單','續租單') NOT NULL DEFAULT '普通單' COMMENT '類型', `relate_id` int(11) unsigned DEFAULT '0' COMMENT '關聯id', `remark` varchar(1000) DEFAULT '' COMMENT '備注', `status` enum('未支付','租賃中','已結束') DEFAULT '未支付' COMMENT '狀態', `finish_time` datetime DEFAULT NULL COMMENT '結束時間', `pay_time` datetime DEFAULT NULL COMMENT '支付時間', `pay_status` enum('未支付','已支付') DEFAULT '未支付' COMMENT '支付狀態', `activity_id` int(11) unsigned DEFAULT '0' COMMENT '活動id', `activity_name` varchar(64) DEFAULT '' COMMENT '活動名稱', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='訂單表'; -- ---------------------------- -- Table structure for oxygen_order_blank -- ---------------------------- DROP TABLE IF EXISTS `oxygen_order_blank`; CREATE TABLE `oxygen_order_blank` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `no` char(14) NOT NULL DEFAULT '' COMMENT '單號', `create_time` datetime DEFAULT NULL COMMENT '申請時間', `creator_uid` bigint(20) unsigned DEFAULT '0' COMMENT '創建者uid', `check_time` datetime DEFAULT NULL COMMENT '審核時間', `name` varchar(64) DEFAULT '' COMMENT '網點名稱', `stock_time` datetime DEFAULT NULL COMMENT '入庫時間', `deliver_address` varchar(128) DEFAULT '' COMMENT '配貨地址', `status` enum('待審核','配貨中','已入庫') DEFAULT '待審核', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='配貨單'; -- ---------------------------- -- Table structure for oxygen_order_blank_detail -- ---------------------------- DROP TABLE IF EXISTS `oxygen_order_blank_detail`; CREATE TABLE `oxygen_order_blank_detail` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `order_blank_id` int(11) unsigned DEFAULT '0' COMMENT '配貨單id', `name` varchar(11) NOT NULL DEFAULT '' COMMENT '項目名稱', `amount` int(11) unsigned DEFAULT '0' COMMENT '數量', `unit` varchar(16) DEFAULT '' COMMENT '單位', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='配貨單明細'; -- ---------------------------- -- Table structure for oxygen_order_detail -- ---------------------------- DROP TABLE IF EXISTS `oxygen_order_detail`; CREATE TABLE `oxygen_order_detail` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL DEFAULT '' COMMENT '產品名稱', `price` float(10,2) unsigned DEFAULT '0.00' COMMENT '價格', `amount` int(11) unsigned DEFAULT '1' COMMENT '數量', `total` float(10,2) unsigned DEFAULT '0.00' COMMENT '總價', `sn` varchar(32) DEFAULT '' COMMENT '序列號', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='訂單明細'; -- ---------------------------- -- Table structure for oxygen_product -- ---------------------------- DROP TABLE IF EXISTS `oxygen_product`; CREATE TABLE `oxygen_product` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `type` enum('產品','配件') DEFAULT '產品' COMMENT '類型', `name` varchar(64) NOT NULL DEFAULT '' COMMENT '名稱', `unit` varchar(16) DEFAULT '' COMMENT '單位', `mode` enum('出租','銷售') DEFAULT '出租' COMMENT '租售模式', `create_time` datetime DEFAULT NULL, `update_time` datetime DEFAULT NULL COMMENT '更新時間', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='產品表'; -- ---------------------------- -- Table structure for oxygen_repaire_list -- ---------------------------- DROP TABLE IF EXISTS `oxygen_repaire_list`; CREATE TABLE `oxygen_repaire_list` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `no` char(14) NOT NULL DEFAULT '' COMMENT '單號', `create_time` datetime DEFAULT NULL COMMENT '申請時間', `uid` int(11) unsigned DEFAULT '0' COMMENT '網點uid', `deliver_address` varchar(32) DEFAULT '' COMMENT '收貨地址', `check_time` datetime DEFAULT NULL COMMENT '審核時間', `stock_time` datetime DEFAULT NULL COMMENT '入庫時間', `name` varchar(64) DEFAULT '' COMMENT '網點名稱', `status` enum('待審核','取貨中','已取貨') DEFAULT '待審核' COMMENT '狀態', `check_uid` int(11) unsigned DEFAULT '0' COMMENT '審核人uid', `stock_uid` int(11) unsigned DEFAULT '0' COMMENT '入庫uid', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='報修單'; -- ---------------------------- -- Table structure for oxygen_repaire_list_detail -- ---------------------------- DROP TABLE IF EXISTS `oxygen_repaire_list_detail`; CREATE TABLE `oxygen_repaire_list_detail` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `oxygen_repaire_list_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '報修單id', `name` varchar(32) DEFAULT '' COMMENT '商品名稱', `amount` int(11) unsigned DEFAULT '0' COMMENT '數據', `unit` varchar(16) DEFAULT '' COMMENT '單位', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='報修單明細'; -- ---------------------------- -- Table structure for oxygen_report_lose -- ---------------------------- DROP TABLE IF EXISTS `oxygen_report_lose`; CREATE TABLE `oxygen_report_lose` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `no` char(24) NOT NULL DEFAULT '' COMMENT '單號', `create_time` datetime DEFAULT NULL COMMENT '申請時間', `uid` int(11) unsigned DEFAULT '0' COMMENT '創建uid', `deliver_address` varchar(128) DEFAULT '' COMMENT '收貨地址', `check_time` datetime DEFAULT NULL COMMENT '審核時間', `stock_time` datetime DEFAULT NULL COMMENT '入庫時間', `name` varchar(0) DEFAULT '' COMMENT '網點名稱', `status` enum('配貨中','待審核','已入庫') DEFAULT '待審核' COMMENT '狀態', `money` float(10,2) unsigned DEFAULT '0.00' COMMENT '應賠金額', `money_left` float(10,2) unsigned DEFAULT '0.00' COMMENT '剩余賠付狀態', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='報損單'; -- ---------------------------- -- Table structure for oxygen_report_lose_detail -- ---------------------------- DROP TABLE IF EXISTS `oxygen_report_lose_detail`; CREATE TABLE `oxygen_report_lose_detail` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `repaire_lose_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '報損單id', `name` varchar(32) DEFAULT '' COMMENT '產品名稱', `amount` int(11) unsigned DEFAULT '0' COMMENT '數量', `unit` varchar(16) DEFAULT '' COMMENT '單位', `price` float(10,2) unsigned DEFAULT '0.00' COMMENT '金額', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='報損單明細'; -- ---------------------------- -- Table structure for oxygen_return -- ---------------------------- DROP TABLE IF EXISTS `oxygen_return`; CREATE TABLE `oxygen_return` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `no` char(14) DEFAULT '' COMMENT '編號', `create_time` datetime DEFAULT NULL COMMENT '申請時間', `uid` int(11) unsigned DEFAULT '0' COMMENT '網點uid', `name` varchar(64) DEFAULT '' COMMENT '網點名稱', `deliver_address` varchar(128) DEFAULT '' COMMENT '收貨地址', `check_time` datetime DEFAULT NULL COMMENT '審核時間', `stock_time` datetime DEFAULT NULL COMMENT '入庫時間', `status` enum('待審核','配貨中','已退貨') DEFAULT '待審核', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='退貨單'; -- ---------------------------- -- Table structure for oxygen_return_detail -- ---------------------------- DROP TABLE IF EXISTS `oxygen_return_detail`; CREATE TABLE `oxygen_return_detail` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `oxygen_return_id` int(11) unsigned DEFAULT '0', `name` varchar(64) DEFAULT '' COMMENT '名稱', `amount` int(10) unsigned DEFAULT '0' COMMENT '數量', `unit` varchar(16) DEFAULT '' COMMENT '單位', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='退貨單明細'; -- ---------------------------- -- Table structure for oxygen_user_extra -- ---------------------------- DROP TABLE IF EXISTS `oxygen_user_extra`; CREATE TABLE `oxygen_user_extra` ( `uid` bigint(20) unsigned NOT NULL, `creator_uid` int(11) unsigned DEFAULT '0' COMMENT '創建者uid', `info` json DEFAULT NULL COMMENT '擴展信息', PRIMARY KEY (`uid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用戶擴展信息表'; -- ---------------------------- -- Table structure for oxygen_wxuser -- ---------------------------- DROP TABLE IF EXISTS `oxygen_wxuser`; CREATE TABLE `oxygen_wxuser` ( `uid` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '用戶uid', `appid` varchar(32) CHARACTER SET utf8 NOT NULL COMMENT '微信appid', `session_key` varchar(24) CHARACTER SET utf8 DEFAULT '' COMMENT 'session_key', `unionid` varchar(64) CHARACTER SET utf8 DEFAULT '' COMMENT '開放平臺openid', `type` enum('小程序','公眾號') CHARACTER SET utf8 DEFAULT '小程序' COMMENT '類型', `nickname` varchar(64) DEFAULT '' COMMENT '昵稱', `sex` enum('男','女','未知') CHARACTER SET utf8 NOT NULL DEFAULT '未知' COMMENT '性別', `language` varchar(16) DEFAULT '' COMMENT '語言', `province` varchar(32) CHARACTER SET utf8 DEFAULT '' COMMENT '省', `city` varchar(32) CHARACTER SET utf8 DEFAULT '' COMMENT '市', `country` varchar(32) CHARACTER SET utf8 DEFAULT '' COMMENT '國家', `headimgurl` varchar(255) CHARACTER SET utf8 DEFAULT '' COMMENT '頭像', `lease_times` int(11) unsigned DEFAULT '0' COMMENT '租賃次數', `lease_time` int(11) unsigned DEFAULT '0' COMMENT '租賃時長', `lease_money` float(10,2) unsigned DEFAULT '0.00' COMMENT '租賃金額', `lease_last_order_time` datetime DEFAULT NULL COMMENT '最后租賃時間', `lease_last_order_return_time` datetime DEFAULT NULL COMMENT '最后歸還時間', `lease_last_order_money` float(10,2) unsigned DEFAULT '0.00' COMMENT '最后租賃金額', PRIMARY KEY (`uid`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信用戶表'; ~~~ | 設備 | 數量 |單位| | --- | --- | --- | |便攜式制氧機套裝|100|套| |充電寶|20|只| |鼻氧管|200|根| ## inotify 的安裝 一、安裝 1)? 從內核和目錄里面查看是否支持inotify [root@nfs01 ~]#?**uname -r** **2.6.32-573.el6.x86_64** [root@nfs01 ~]#**?ls -l /proc/sys/fs/inotify/**??? -→主要查看下面有沒有三個目錄 總用量 0 -rw-r--r-- 1 root root 0 1月? 21 13:03 max_queued_events -rw-r--r-- 1 root root 0 1月? 21 13:03 max_user_instances -rw-r--r-- 1 root root 0 1月? 21 13:03 max_user_watches **2****)檢查是否有安裝inotify?****如果沒有就安裝** **rpm -qa inotify-tools** 沒有就先安裝epol源 yum.repos.d]#?**wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo** 之后安裝 [root@nfs01 ~]#**?yum install inotify-tools -y** **二、參數講解、** [root@nfs01 ~]#?**which inotifywait** **/usr/bin/inotifywait** [root@nfsserver inotify-tools]#?**bin/inotifywait —help** r :遞歸查詢目錄 q:打印很少的信息,僅僅打印監控事件的信息? 安靜狀態 m:始終保持事件監聽狀態 excluder#排除文件或者目錄的時候不區分大小寫 timefmt:指定時間輸出的格式 d :后臺運行 -e: 事件 里面有很多方法 下面是事件參數 Events: access file or directory contents were read 訪問 modify file or directory contents were written 修改 attrib file or directory attributes changed 屬性發生變化 close_write file or directory closed, after being opened in 寫入之后關閉 writeable mode close_nowrite file or directory closed, after being opened in read-only mode close file or directory closed, regardless of read/write mode open file or directory opened moved_to file or directory moved to watched directory 移動到哪里 moved_from file or directory moved from watched directory move file or directory moved to or from watched directory create file or directory created within watched directory delete file or directory deleted within watched directory delete_self file or directory was deleted unmount file system containing file or directory unmounted卸載 之后就可以和nfs共享服務器之間的實時備份 ## 百度圖片識別 ~~~ function ocr_code($url, $length = 4, $debug =0){ $img = file_get_contents($url); $tmp = tempnam(sys_get_temp_dir(), 'code'); file_put_contents($tmp, $img); $ret = plugin_action('BaiduAi', 'Ocr', 'basicAccurate', [$img]); $words = $ret['words_result'][0]['words']; $words = trim($words, ' '); $words = str_ireplace(['.',' ', '\''], '', $words); if($debug){ echo '<img src="'.base64EncodeImage($tmp).'">'; dump($ret); dump($words); } return strlen($words)== $length? $words: ''; } ~~~ ## 身份證識別 `composer require "douyasi/identity-card:~2.0"` `$ID = new Douyasi\IdentityCard\ID();` `$passed = $ID->validateIDCard('42032319930606629x');` ## 獲取某網站cookie ``` public function get_cookie(){ // @unlink('verify.png'); // @unlink('result.png'); $puppeteer = new Puppeteer([ 'executable_path'=>'/usr/local/bin/node', ]); $browser = $puppeteer->launch([ 'args'=>['--no-sandbox', '--disable-setuid-sandbox'] ]); $domain = is_online()? 'fj.pizhigu.com':'test.pizhigu.com'; // $domain = 'fj.pizhigu.com'; $url = url('/',[], false, $domain).'uploads/verify.png'; $ocr_url = url('/index/service/ocr_code', [], false, $domain); $debug_url = url('/dingding/index/front_log', [], false, $domain); try { $page = $browser->newPage(); $page->goto('http://cpservice.sipo.gov.cn/index.jsp'); $img = $page->querySelector("#Verify"); $usernameInput = $page->querySelector("#username"); $usernameInput->focus(); //定位到用戶名 $page->keyboard->type("91321102338928957N"); $passwordInput = $page->querySelector("#password"); $passwordInput->focus(); $pwd = config('cps_pwd'); $page->keyboard->type($pwd); // $page->screenshot(['path' => 'uploads/result0.png']); $page->screenshot(['path' => 'uploads/verify.png', 'clip'=>[ 'x'=>616,'y'=>546, 'width'=>70,'height'=>30 ] ]); $js = <<<JS var xmlhttp; var ret = '1111'; if (window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); }else{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("POST","{$ocr_url}",false); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("url={$url}"); xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ ret = xmlhttp.responseText; return; } } if (xmlhttp.readyState==4 && xmlhttp.status==200){ ret = xmlhttp.responseText; }else{ xmlhttp.open("GET","{$debug_url}?msg="+ JSON.stringify([xmlhttp.readyState, xmlhttp.status,xmlhttp.responseText, xmlhttp.responseXML]),true); xmlhttp.send(); } return ret; JS; $verifyFunction = JsFunction::createWithBody($js); $dimensions = $page->evaluate($verifyFunction); // dump($dimensions); if($dimensions != '1111' && $dimensions != ''){ $securityCodeInput = $page->querySelector("#securityCode"); $securityCodeInput->focus(); $page->keyboard->type($dimensions); $page->screenshot(['path' => 'uploads/result.png']); $loginFunction = JsFunction::createWithBody(" return login(); "); $dimensions2 = $page->evaluate($loginFunction); $page->waitForNavigation(['timeout'=>10000]); $js = <<<JS var str = document.cookie; str += "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/"; document.cookie = str; return document.cookie; JS; $jumpFunction = JsFunction::createWithBody($js); $dimensions3 = $page->evaluate($jumpFunction); $page->screenshot(['path' => 'uploads/result2.png']); dump($dimensions3); if($dimensions3){ $data = [ 'name' => self::$cpservice_cache, 'value' => $dimensions3, ]; Db::name('service_config')->insertAll([$data], true); $msg = '登錄成功,獲得cookie:'.$dimensions3; }else{ $msg = '登錄失敗碼失敗'; $this->refresh_cookie(); } }else{ $msg = '識別驗證碼失敗'; $this->refresh_cookie(); } // ptrace($msg); trace($msg); } catch (Node\Exception $exception) { // ptrace($e->getMessage().PHP_EOL.$e->getTraceAsString()); trace($e->getMessage().PHP_EOL.$e->getTraceAsString()); } $browser->close(); } ``` ## tcp # tp5_swoole_demo thinkphp5 swoole 演示demo # swoole安裝 ## wsl 去windows應用商店里搜索ubutun 安裝18.64 然后通過oneinstalk 安裝php環境 只是演示的話可以不裝 nginx和數據庫 ```wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --php_option 8 --php_extensions swoole --reboot ``` 因為不是root用戶 拆成兩句執行 ```sudo wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz``` 然后執行 sudo ./oneinstack/install.sh --php_option 8 --php_extensions swoole --reboot > 安裝失敗 ## apt-get sudo apt-get install php7.0 > 安裝失敗 ## lnmp wget http://soft.vpser.net/lnmp/lnmp1.5.tar.gz -cO lnmp1.5.tar.gz && tar zxf lnmp1.5.tar.gz && cd lnmp1.5 && ./install.sh lnmp ### 驗證 php -m 看到swoole擴展即可 # 初始化tp項目 # 安裝think-swoole擴展 在wsl 對應目錄里(cd /mnt/d/wamp64/www/git/tp5_swoole_demo/) 運行 composer require topthink/think-swoole > 切換到wsl 目錄訪問模式下安裝,不然提示擴展未安裝 > sudo pecl install swoole # ptrace array:5 [▼ "chatid" => "chat13280cb4120b6aae2d94fad60bf4a289" "openConversationId" => "cidK2gTCMAZZxg2PxFEm145gw==" "conversationTag" => 2 "errmsg" => "ok" "errcode" => 0 ] # tcp 的實現 ## 類 'swoole_class' => 'app\http\Swoole' 指定一個類 所有的其他配置放在類的 options里 ## 特殊配置 'pid_file'=>'swoole_pid', 'log_file'=>'swoole.log', pid_file 最好設置一下 然后log_file 也指定一下 方便調試 ## 調試階段 daemonize => false 然后就不會記錄日志 ,直接顯示在屏上。 開啟,則會記錄在日志里。 如果程序出錯, 會記錄到 runtime 日期_cli.log里 最后指定 'exception_handle' => 'app\common\lib\Handle', 好統一報錯到你指定的頻道 如我的例子是釘釘。 ## 工具 tcp/udp socket 調試工具。 ## inotify reload 擴展 https://github.com/yangweijie/note/issues/59 # 疑惑 看了think\swoole 的源碼 發現http 服務里 有一個自帶的 monitor 感覺tcp 里配了也不起作用。 官方的pid_file 獲取好像有bug, 按照官方的設置的server php think swoole:server start 后 stop | reload 都不會精確判斷。 如果想 正確控制 啟動 和監控文件變化 ,請參考 [如何用thinkphp5.1和vue 開發一個小游戲] (http://www.hmoore.net/book/yangweijie/how_to_develop_one_game_with_tp5_1_vue/dashboard) 里的 類里自己自定義 構造方法 后 手動判斷是否啟動后 執行init 方法。 ## 效果圖 ![](https://box.kancloud.cn/e86fd96c6efee051479e8a3fda88ec61_757x72.png) ![](https://box.kancloud.cn/7847b1c9c84172ec14a14040fc369290_698x155.png) ![](https://box.kancloud.cn/3415f65ee7caa56592d5d42b78605362_910x553.png) ![](https://box.kancloud.cn/271d5ea76175965626ac4e8cd1f3de4e_1286x223.png) # 中文路徑 特殊符號給前端下載的問題 后端生成的中文名附件 給前端 base64encode 一下 然后接受的傳后端 path 參數 去下載 結果報 is_file not a valid path 對比發現 url 上 是+ 到php獲取時變空格了 `$path = str_ireplace(' ', '+', $path); ` 替換后 就能正常解析了 # tp6 里 跨域中間件和jwt沖突的問題 jwt包默認需要header頭里傳一個http-x-token 的key 開啟跨域包后 被重置 了, 以前不知道如何給默認中間件傳變量,經過閱讀源碼時發現了 /** * 加載全局中間件 */ protected function loadMiddleware(): void { if (is_file($this->app->getBasePath() . 'middleware.php')) { $this->app->middleware->import(include $this->app->getBasePath() . 'middleware.php'); } } 會將應用目錄下的middleware 數組傳入, /** * 導入中間件 * @access public * @param array $middlewares * @param string $type 中間件類型 * @return void */ public function import(array $middlewares = [], string $type = 'global'): void { foreach ($middlewares as $middleware) { $this->add($middleware, $type); } } /** * 注冊中間件 * @access public * @param mixed $middleware * @param string $type 中間件類型 * @return void */ public function add($middleware, string $type = 'global'): void { $middleware = $this->buildMiddleware($middleware, $type); if (!empty($middleware)) { $this->queue[$type][] = $middleware; $this->queue[$type] = array_unique($this->queue[$type], SORT_REGULAR); } } /** * 解析中間件 * @access protected * @param mixed $middleware * @param string $type 中間件類型 * @return array */ protected function buildMiddleware($middleware, string $type): array { if (is_array($middleware)) { [$middleware, $params] = $middleware; } if ($middleware instanceof Closure) { return [$middleware, $params ?? []]; } if (!is_string($middleware)) { throw new InvalidArgumentException('The middleware is invalid'); } //中間件別名檢查 $alias = $this->app->config->get('middleware.alias', []); if (isset($alias[$middleware])) { $middleware = $alias[$middleware]; } if (is_array($middleware)) { $this->import($middleware, $type); return []; } return [[$middleware, 'handle'], $params ?? []]; } ?如果是閉包直接執行,如果非閉包就會走中間件的handle方法 ?經過我的實驗 ~~~ <?php // 全局中間件定義文件 return [ // 全局請求緩存 // \think\middleware\CheckRequestCache::class, // 多語言加載 // \think\middleware\LoadLangPack::class, // Session初始化 // \think\middleware\SessionInit::class [ \think\middleware\AllowCrossDomain::class, [ [ 'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With,http-x-token,1234' ] ] ], ]; ~~~ 這么配置 是可以覆蓋 AllowCrossDomain handle方法的第三個參數的, 記得你開啟的全局類名 和參數放在一個數組里,參數本身里也是個數組 每個值是后面可變參數的展開 /** * 允許跨域請求 * @access public * @param Request $request * @param Closure $next * @param array $header * @return Response */ public function handle($request, Closure $next, ?array $header = []) { **格式字串可以識別以下`format`參數的字符串** | `format`字符 | 說明 | 返回值例子 | | --- | --- | --- | | *日* | \--- | \--- | | *d* | 月份中的第幾天,有前導零的 2 位數字 | *01*到*31* | | *D* | 星期中的第幾天,文本表示,3 個字母 | *Mon*到*Sun* | | *j* | 月份中的第幾天,沒有前導零 | *1*到*31* | | *l*("L"的小寫字母) | 星期幾,完整的文本格式 | *Sunday*到*Saturday* | | *N* | ISO-8601 格式數字表示的星期中的第幾天(PHP 5.1.0 新加) | *1*(表示星期一)到*7*(表示星期天) | | *S* | 每月天數后面的英文后綴,2 個字符 | *st*,*nd*,*rd*? ? ? ?或者*th*。可以和*j*一起用 | | *w* | 星期中的第幾天,數字表示 | *0*(表示星期天)到*6*(表示星期六) | | *z* | 年份中的第幾天 | *0*到*365* | | *星期* | \--- | \--- | | *W* | ISO-8601 格式年份中的第幾周,每周從星期一開始(PHP 4.1.0 新加的) | 例如:*42*(當年的第 42 周) | | *月* | \--- | \--- | | *F* | 月份,完整的文本格式,例如 January 或者 March | *January*到*December* | | *m* | 數字表示的月份,有前導零 | *01*到*12* | | *M* | 三個字母縮寫表示的月份 | *Jan*到*Dec* | | *n* | 數字表示的月份,沒有前導零 | *1*到*12* | | *t* | 給定月份所應有的天數 | *28*到*31* | | *年* | \--- | \--- | | *L* | 是否為閏年 | 如果是閏年為*1*,否則為*0* | | *o* | ISO-8601 格式年份數字。這和 ? ? ? ?*Y*的值相同,只除了如果 ISO ? ? ? ?的星期數(*W*)屬于前一年或下一年,則用那一年。(PHP 5.1.0 新加) | Examples:*1999*or*2003* | | *Y* | 4 位數字完整表示的年份 | 例如:*1999*或*2003* | | *y* | 2 位數字表示的年份 | 例如:*99*或*03* | | *時間* | \--- | \--- | | *a* | 小寫的上午和下午值 | *am*或*pm* | | *A* | 大寫的上午和下午值 | *AM*或*PM* | | *B* | Swatch Internet 標準時 | *000*到*999* | | *g* | 小時,12 小時格式,沒有前導零 | *1*到*12* | | *G* | 小時,24 小時格式,沒有前導零 | *0*到*23* | | *h* | 小時,12 小時格式,有前導零 | *01*到*12* | | *H* | 小時,24 小時格式,有前導零 | *00*到*23* | | *i* | 有前導零的分鐘數 | *00*到*59*\> | | *s* | 秒數,有前導零 | *00*到*59*\> | | *u* | 毫秒 (PHP 5.2.2 新加)。需要注意的是 ? ? ? ? ? ?**date()**函數總是返回 ? ? ? ? ? ?*000000*因為它只接受integer? ? ? ? ? ?參數, 而DateTime::format()才支持毫秒。 | 示例:*654321* | | *時區* | \--- | \--- | | *e* | 時區標識(PHP 5.1.0 新加) | 例如:*UTC*,*GMT*,*Atlantic/Azores* | | *I* | 是否為夏令時 | 如果是夏令時為*1*,否則為*0* | | *O* | 與格林威治時間相差的小時數 | 例如:*+0200* | | *P* | 與格林威治時間(GMT)的差別,小時和分鐘之間有冒號分隔(PHP 5.1.3 新加) | 例如:*+02:00* | | *T* | 本機所在的時區 | 例如:*EST*,*MDT*(【譯者注】在 Windows ? ? ? 下為完整文本格式,例如"Eastern Standard Time",中文版會顯示"中國標準時間")。 | | *Z* | 時差偏移量的秒數。UTC 西邊的時區偏移量總是負的,UTC 東邊的時區偏移量總是正的。 | *\-43200*到*43200* | | *完整的日期/時間* | \--- | \--- | | *c* | ISO 8601 格式的日期(PHP 5 新加) | 2004-02-12T15:19:21+00:00 | | *r* | RFC 822 格式的日期 | 例如:*Thu, 21 Dec 2000 16:01:07 +0200* | | *U* | 從 Unix 紀元(January 1 1970 00:00:00 GMT)開始至今的秒數 | 參見time() | ?
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看