├── .gitignore ├── README.md ├── docs ├── .vuepress │ ├── config.js │ ├── init.js │ ├── public │ │ ├── Images │ │ │ └── easyswoole.png │ │ ├── bdtj.js │ │ ├── favicon.ico │ │ ├── install.sh │ │ ├── playVideo.html │ │ ├── resources │ │ │ ├── authWx.png │ │ │ ├── banner.png │ │ │ ├── ckplayer │ │ │ │ ├── ckplayer.js │ │ │ │ ├── ckplayer.min.js │ │ │ │ ├── ckplayer.swf │ │ │ │ ├── ckplayer.xml │ │ │ │ ├── hls │ │ │ │ │ ├── LICENSE │ │ │ │ │ ├── hls.js │ │ │ │ │ └── hls.min.js │ │ │ │ ├── language.xml │ │ │ │ └── style.xml │ │ │ ├── coroutine.png │ │ │ ├── donate.png │ │ │ ├── easyWhoops.png │ │ │ ├── hero.png │ │ │ ├── hero.svg │ │ │ ├── img1.png │ │ │ ├── img2.png │ │ │ ├── img3.png │ │ │ ├── img4.png │ │ │ ├── img5.png │ │ │ ├── img6.png │ │ │ ├── logo.png │ │ │ ├── logo@2x.psd │ │ │ ├── openSource │ │ │ │ └── xlsWriter.png │ │ │ ├── partner │ │ │ │ ├── 360finance.png │ │ │ │ ├── 360games.png │ │ │ │ ├── 9377games.png │ │ │ │ ├── LOGO.psd │ │ │ │ ├── chandashi.png │ │ │ │ ├── meitu.png │ │ │ │ ├── tencent.png │ │ │ │ ├── wangsu.png │ │ │ │ └── yuanchu.png │ │ │ ├── rpcDesign.png │ │ │ └── wx_donate.png │ │ ├── wsTool │ │ │ ├── format.js │ │ │ ├── socket.js │ │ │ └── wstool.css │ │ └── wstool.html │ ├── sidebar.js │ └── theme │ │ ├── components │ │ ├── Home.vue │ │ ├── Navbar.vue │ │ └── PartnerCard.vue │ │ ├── index.js │ │ ├── package-lock.json │ │ ├── package.json │ │ └── yarn.lock ├── Article │ ├── degradedService.md │ ├── learnSwoole.md │ ├── swooleIpLimit.md │ └── websocket.md ├── BaseUsage │ ├── crontab.md │ ├── customCommand.md │ ├── event.md │ ├── log.md │ └── serverManager.md ├── Components │ ├── Actor │ │ ├── actor.md │ │ └── analysis.md │ ├── Component │ │ ├── atomic.md │ │ ├── context.md │ │ ├── coroutineSingleton.md │ │ ├── csp.md │ │ ├── ioc.md │ │ ├── process.md │ │ ├── readyScheduler.md │ │ ├── singleton.md │ │ ├── tableManager.md │ │ ├── timer.md │ │ └── waitGroup.md │ ├── FastCache │ │ ├── fastCache.md │ │ └── fastCacheQueue.md │ ├── HttpClient │ │ ├── introduction.md │ │ ├── request.md │ │ ├── response.md │ │ └── webSocket.md │ ├── Jwt │ │ ├── decode.md │ │ ├── encode.md │ │ ├── images │ │ │ └── framework.png │ │ ├── introduction.md │ │ └── use.md │ ├── Memcache │ │ ├── memcache.md │ │ └── pool.md │ ├── Mysqli │ │ ├── Chain │ │ │ ├── deleteMethod.md │ │ │ ├── fieldsMethod.md │ │ │ ├── getMethod.md │ │ │ ├── getOneMethod.md │ │ │ ├── groupbyMethod.md │ │ │ ├── havingMethod.md │ │ │ ├── insertMethod.md │ │ │ ├── joinMethod.md │ │ │ ├── joinOrWhereMethod.md │ │ │ ├── joinWhereMethod.md │ │ │ ├── limitMethod.md │ │ │ ├── lockInShareModeMethod.md │ │ │ ├── lockTableMethod.md │ │ │ ├── onDuplicateMethod.md │ │ │ ├── orHavingMethod.md │ │ │ ├── orWhereMethod.md │ │ │ ├── orderbyMethod.md │ │ │ ├── replaceMethod.md │ │ │ ├── selectForUpdateMethod.md │ │ │ ├── setLockTableModeMethod.md │ │ │ ├── setPrefixMethod.md │ │ │ ├── setQueryOptionMethod.md │ │ │ ├── unionMethod.md │ │ │ ├── unlockTableMethod.md │ │ │ ├── updateMethod.md │ │ │ ├── whereMethod.md │ │ │ └── withTotalCountMethod.md │ │ ├── builder.md │ │ ├── delete.md │ │ ├── insert.md │ │ ├── install.md │ │ ├── mysqli.md │ │ ├── query.md │ │ └── update.md │ ├── Orm │ │ ├── Associat │ │ │ ├── oneToManyAssociations.md │ │ │ ├── oneToOneAssociations.md │ │ │ └── preWithQuery.md │ │ ├── DefineModel │ │ │ ├── defineTableStructure.md │ │ │ ├── specifyConnectionName.md │ │ │ └── timestamp.md │ │ ├── Event │ │ │ ├── model.md │ │ │ └── onQuery.md │ │ ├── add.md │ │ ├── aggregation.md │ │ ├── coherentOperation.md │ │ ├── configurationRegister.md │ │ ├── customSqlExecution.md │ │ ├── defineModel.md │ │ ├── delete.md │ │ ├── getter.md │ │ ├── install.md │ │ ├── invoke.md │ │ ├── lastQuery.md │ │ ├── lastResult.md │ │ ├── modifier.md │ │ ├── popularScienceConcept.md │ │ ├── query.md │ │ ├── quickQuery.md │ │ ├── readWriteSeparation.md │ │ ├── specialQuery.md │ │ ├── transactionOperations.md │ │ └── update.md │ ├── Pay │ │ ├── ali.md │ │ └── wechat.md │ ├── Pool │ │ ├── abstractPool.md │ │ ├── config.md │ │ ├── demo.md │ │ ├── introduction.md │ │ ├── poolManage.md │ │ └── whyUsePool.md │ ├── Queue │ │ ├── driver.md │ │ ├── install.md │ │ └── usage.md │ ├── Redis │ │ ├── cluster.md │ │ ├── clusterMethod.md │ │ ├── config.md │ │ ├── connection.md │ │ ├── error.md │ │ ├── geoHash.md │ │ ├── hash.md │ │ ├── hyperLogLog.md │ │ ├── install.md │ │ ├── introduction.md │ │ ├── keys.md │ │ ├── lists.md │ │ ├── pipe.md │ │ ├── pool.md │ │ ├── pubSub.md │ │ ├── rawCommand.md │ │ ├── redis.md │ │ ├── sets.md │ │ ├── sortedSets.md │ │ ├── string.md │ │ └── transaction.md │ ├── Rpc │ │ ├── client.md │ │ ├── introduction.md │ │ ├── otherPlatform.md │ │ ├── registerCenter.md │ │ ├── server.md │ │ └── service.md │ ├── Smtp │ │ ├── config.md │ │ ├── content.md │ │ ├── contentconfig.md │ │ ├── image │ │ │ ├── html.png │ │ │ └── text.png │ │ └── smtp.md │ ├── Spl │ │ ├── splArray.md │ │ ├── splBean.md │ │ ├── splEnum.md │ │ ├── splFileStream.md │ │ ├── splStream.md │ │ └── splString.md │ ├── Sundries │ │ ├── arrayToTextTable.md │ │ ├── file.md │ │ ├── hash.md │ │ ├── random.md │ │ ├── snowFlake.md │ │ ├── str.md │ │ └── time.md │ ├── SyncInvoker │ │ ├── mongoDb.md │ │ └── syncInvoker.md │ ├── VerifyCode │ │ ├── config.md │ │ ├── introduction.md │ │ └── verifyCode.md │ ├── Wechat │ │ ├── miniProgram.md │ │ └── officialAccount.md │ ├── WordsMatch │ │ ├── WordsMatch.md │ │ └── ab.md │ ├── annotation.md │ ├── apollo.md │ ├── atomicLimit.md │ ├── console.md │ ├── consul.md │ ├── ddl.md │ ├── hotReload.md │ ├── kafka.md │ ├── oss.md │ ├── phpunit.md │ ├── policy.md │ ├── redisPool.md │ ├── task.md │ ├── template.md │ ├── tracker.md │ └── whoops.md ├── Core │ ├── event.md │ ├── event │ │ ├── afterRequest.md │ │ ├── bootstrap.md │ │ ├── initialize.md │ │ ├── mainServerCreate.md │ │ ├── onReceive.md │ │ └── onRequest.md │ ├── lifecycle.md │ ├── lifecycle.png │ └── other.md ├── Distribute │ ├── atomicLimit.md │ ├── loadbalance.md │ └── microService.md ├── En │ ├── Article │ │ ├── degradedService.md │ │ ├── learnSwoole.md │ │ └── swooleIpLimit.md │ ├── BaseUsage │ │ ├── crontab.md │ │ ├── customCommand.md │ │ ├── event.md │ │ ├── log.md │ │ └── serverManager.md │ ├── Components │ │ ├── Actor │ │ │ ├── actor.md │ │ │ └── analysis.md │ │ ├── Component │ │ │ ├── atomic.md │ │ │ ├── context.md │ │ │ ├── coroutineSingleton.md │ │ │ ├── csp.md │ │ │ ├── ioc.md │ │ │ ├── process.md │ │ │ ├── readyScheduler.md │ │ │ ├── singleton.md │ │ │ ├── tableManager.md │ │ │ ├── timer.md │ │ │ └── waitGroup.md │ │ ├── FastCache │ │ │ ├── fastCache.md │ │ │ └── fastCacheQueue.md │ │ ├── HttpClient │ │ │ ├── introduction.md │ │ │ ├── request.md │ │ │ ├── response.md │ │ │ └── webSocket.md │ │ ├── Jwt │ │ │ ├── decode.md │ │ │ ├── encode.md │ │ │ ├── images │ │ │ │ └── framework.png │ │ │ ├── introduction.md │ │ │ └── use.md │ │ ├── Memcache │ │ │ ├── memcache.md │ │ │ └── pool.md │ │ ├── Mysqli │ │ │ ├── Chain │ │ │ │ ├── deleteMethod.md │ │ │ │ ├── fieldsMethod.md │ │ │ │ ├── getMethod.md │ │ │ │ ├── getOneMethod.md │ │ │ │ ├── groupbyMethod.md │ │ │ │ ├── havingMethod.md │ │ │ │ ├── insertMethod.md │ │ │ │ ├── joinMethod.md │ │ │ │ ├── joinOrWhereMethod.md │ │ │ │ ├── joinWhereMethod.md │ │ │ │ ├── limitMethod.md │ │ │ │ ├── lockInShareModeMethod.md │ │ │ │ ├── lockTableMethod.md │ │ │ │ ├── onDuplicateMethod.md │ │ │ │ ├── orHavingMethod.md │ │ │ │ ├── orWhereMethod.md │ │ │ │ ├── orderbyMethod.md │ │ │ │ ├── replaceMethod.md │ │ │ │ ├── selectForUpdateMethod.md │ │ │ │ ├── setLockTableModeMethod.md │ │ │ │ ├── setPrefixMethod.md │ │ │ │ ├── setQueryOptionMethod.md │ │ │ │ ├── unionMethod.md │ │ │ │ ├── unlockTableMethod.md │ │ │ │ ├── updateMethod.md │ │ │ │ ├── whereMethod.md │ │ │ │ └── withTotalCountMethod.md │ │ │ ├── builder.md │ │ │ ├── delete.md │ │ │ ├── insert.md │ │ │ ├── install.md │ │ │ ├── query.md │ │ │ └── update.md │ │ ├── Orm │ │ │ ├── Associat │ │ │ │ ├── oneToManyAssociations.md │ │ │ │ ├── oneToOneAssociations.md │ │ │ │ └── preWithQuery.md │ │ │ ├── DefineModel │ │ │ │ ├── defineTableStructure.md │ │ │ │ ├── specifyConnectionName.md │ │ │ │ └── timestamp.md │ │ │ ├── Event │ │ │ │ ├── model.md │ │ │ │ └── onQuery.md │ │ │ ├── add.md │ │ │ ├── aggregation.md │ │ │ ├── coherentOperation.md │ │ │ ├── configurationRegister.md │ │ │ ├── customSqlExecution.md │ │ │ ├── defineModel.md │ │ │ ├── delete.md │ │ │ ├── getter.md │ │ │ ├── install.md │ │ │ ├── invokeExecution.md │ │ │ ├── lastQuery.md │ │ │ ├── lastResult.md │ │ │ ├── modifier.md │ │ │ ├── popularScienceConcept.md │ │ │ ├── query.md │ │ │ ├── quickQuery.md │ │ │ ├── readWriteSeparation.md │ │ │ ├── specialQuery.md │ │ │ ├── transactionOperations.md │ │ │ └── update.md │ │ ├── Pool │ │ │ ├── abstractPool.md │ │ │ ├── config.md │ │ │ ├── demo.md │ │ │ ├── introduction.md │ │ │ └── poolManage.md │ │ ├── Queue │ │ │ ├── driver.md │ │ │ ├── install.md │ │ │ └── usage.md │ │ ├── Redis │ │ │ ├── cluster.md │ │ │ ├── clusterMethod.md │ │ │ ├── config.md │ │ │ ├── connection.md │ │ │ ├── geoHash.md │ │ │ ├── hash.md │ │ │ ├── hyperLogLog.md │ │ │ ├── install.md │ │ │ ├── introduction.md │ │ │ ├── keys.md │ │ │ ├── lists.md │ │ │ ├── pipe.md │ │ │ ├── pool.md │ │ │ ├── pubSub.md │ │ │ ├── redis.md │ │ │ ├── sets.md │ │ │ ├── sortedSets.md │ │ │ ├── string.md │ │ │ └── transaction.md │ │ ├── Rpc │ │ │ ├── client.md │ │ │ ├── introduction.md │ │ │ ├── otherPlatform.md │ │ │ ├── registerCenter.md │ │ │ └── server.md │ │ ├── Spl │ │ │ ├── splArray.md │ │ │ ├── splBean.md │ │ │ ├── splEnum.md │ │ │ ├── splFileStream.md │ │ │ ├── splStream.md │ │ │ └── splString.md │ │ ├── Sundries │ │ │ ├── arrayToTextTable.md │ │ │ ├── file.md │ │ │ ├── hash.md │ │ │ ├── random.md │ │ │ ├── snowFlake.md │ │ │ ├── str.md │ │ │ └── time.md │ │ ├── SyncInvoker │ │ │ ├── mongoDb.md │ │ │ └── syncInvoker.md │ │ ├── VerifyCode │ │ │ ├── config.md │ │ │ ├── introduction.md │ │ │ └── verifyCode.md │ │ ├── WordsMatch │ │ │ ├── WordsMatch.md │ │ │ └── ab.md │ │ ├── annotation.md │ │ ├── apollo.md │ │ ├── atomicLimit.md │ │ ├── console.md │ │ ├── consul.md │ │ ├── ddl.md │ │ ├── hotReload.md │ │ ├── kafka.md │ │ ├── mysqli.md │ │ ├── phpunit.md │ │ ├── policy.md │ │ ├── redisPool.md │ │ ├── task.md │ │ ├── template.md │ │ ├── tracker.md │ │ └── whoops.md │ ├── Core │ │ ├── event.md │ │ ├── event │ │ │ ├── afterRequest.md │ │ │ ├── bootstrap.md │ │ │ ├── initialize.md │ │ │ ├── mainServerCreate.md │ │ │ ├── onReceive.md │ │ │ └── onRequest.md │ │ ├── lifecycle.md │ │ ├── lifecycle.png │ │ └── other.md │ ├── Distribute │ │ ├── atomicLimit.md │ │ ├── loadbalance.md │ │ └── microService.md │ ├── HttpServer │ │ ├── annotation.md │ │ ├── controller.md │ │ ├── dispatch.md │ │ ├── exception.md │ │ ├── fastRoute.md │ │ ├── introduction.md │ │ ├── problem.md │ │ ├── psr7.md │ │ ├── request.md │ │ ├── response.md │ │ ├── session.md │ │ ├── static.md │ │ ├── template.md │ │ ├── uploadFile.md │ │ └── validate.md │ ├── Introduction │ │ ├── config.md │ │ ├── coroutineCreate.md │ │ ├── demo.md │ │ ├── docker.md │ │ ├── environment.md │ │ ├── example.md │ │ ├── helloWorld.md │ │ ├── install.md │ │ ├── proxy.md │ │ └── server.md │ ├── Other │ │ ├── chromeHeadless.md │ │ ├── curlSsl.md │ │ ├── graphQL.md │ │ ├── hotReload.md │ │ ├── kernelOptimization.md │ │ ├── mysqlIndexReduce.md │ │ ├── process.md │ │ ├── random.md │ │ ├── redisSubscribe.md │ │ ├── swooleTracker.md │ │ ├── tpORM.md │ │ └── traitSingleTon.md │ ├── Preface │ │ ├── componentUpdateLog.md │ │ ├── contactAuthor.md │ │ ├── developerRead.md │ │ ├── donation.md │ │ ├── introduction.md │ │ ├── team.md │ │ └── updateLog.md │ ├── README.md │ ├── Sdk │ │ ├── miniProgram.md │ │ ├── openPlatform.md │ │ ├── pay.md │ │ ├── wechat.md │ │ └── wxPay.md │ └── Socket │ │ ├── question.md │ │ ├── tcp.md │ │ ├── tcpSticky.md │ │ ├── udp.md │ │ ├── webSocket.md │ │ ├── webSocketShake.md │ │ └── webSocketWss.md ├── HttpServer │ ├── annotation.md │ ├── controller.md │ ├── dispatch.md │ ├── exception.md │ ├── fastRoute.md │ ├── introduction.md │ ├── problem.md │ ├── psr7.md │ ├── request.md │ ├── response.md │ ├── session.md │ ├── static.md │ ├── template.md │ ├── uploadFile.md │ └── validate.md ├── Introduction │ ├── config.md │ ├── coroutineCreate.md │ ├── demo.md │ ├── docker.md │ ├── environment.md │ ├── example.md │ ├── helloWorld.md │ ├── install.md │ ├── proxy.md │ └── server.md ├── NoobCourse │ ├── ArtOfAskingQuestions.md │ ├── Async.png │ ├── Block.md │ ├── Composer.md │ ├── Conversation │ │ ├── Cookie.md │ │ ├── Introduction.md │ │ ├── Session.md │ │ └── token.md │ ├── Coroutine.md │ ├── Coroutine.png │ ├── EasySwoole │ │ ├── Demo.md │ │ ├── DesignIdea.md │ │ ├── Introduction.md │ │ ├── RunSteps.md │ │ └── Section.md │ ├── Introduction.md │ ├── Linux.md │ ├── Linux │ │ ├── Command.md │ │ ├── Extention.md │ │ ├── Firewall.md │ │ ├── Introduction.md │ │ ├── Lnmp.md │ │ ├── Port.md │ │ └── Process.md │ ├── NetworkrPotocol │ │ ├── Introduction.md │ │ ├── ip.md │ │ ├── networkPotocol.png │ │ ├── port.md │ │ ├── tcp │ │ │ ├── http.jpg │ │ │ ├── http.md │ │ │ ├── tcp.md │ │ │ ├── websocket.jpg │ │ │ └── websocket.md │ │ └── udp.md │ ├── PHP │ │ ├── Callback.md │ │ ├── Closures.md │ │ ├── Multiprocess │ │ │ ├── Deamon.md │ │ │ ├── Introduction.md │ │ │ ├── OrphanProcess.md │ │ │ ├── OrphanProcess.png │ │ │ ├── ProcessCommunication.md │ │ │ ├── ProcessSignal.md │ │ │ ├── ZombieProcess.md │ │ │ └── fork.md │ │ └── Php7.md │ ├── RunMode │ │ ├── Introduction.md │ │ ├── php-cli │ │ │ └── Introduction.md │ │ └── php-fpm.md │ ├── Swoole │ │ ├── Lifecycle.md │ │ ├── RunningMode.md │ │ └── Start.md │ └── Sync.md ├── OpenSource │ └── xlsWriter.md ├── Other │ ├── chromeHeadless.md │ ├── curlSsl.md │ ├── graphQL.md │ ├── hotReload.md │ ├── kernelOptimization.md │ ├── mysqlIndexReduce.md │ ├── process.md │ ├── random.md │ ├── redisSubscribe.md │ ├── swooleTracker.md │ ├── tpORM.md │ └── traitSingleTon.md ├── Preface │ ├── componentUpdateLog.md │ ├── contactAuthor.md │ ├── developerRead.md │ ├── donation.md │ ├── introduction.md │ ├── team.md │ └── updateLog.md ├── README.md ├── Sdk │ ├── miniProgram.md │ ├── openPlatform.md │ ├── pay.md │ ├── wechat.md │ └── wxPay.md ├── Socket │ ├── question.md │ ├── tcp.md │ ├── tcpSticky.md │ ├── udp.md │ ├── webSocket.md │ ├── webSocketShake.md │ └── webSocketWss.md └── Video │ ├── 404.md │ ├── base.md │ ├── database.md │ ├── http.md │ ├── introduction.md │ ├── orm.md │ └── other.md ├── git-pull.sh └── package.json /README.md: -------------------------------------------------------------------------------- 1 | # 文档系统 2 | 3 | https://vuepress.vuejs.org/zh/ 4 | 5 | ### 构建 6 | 7 | 命令行执行 `scoop install yarn 8 | ` 安装依赖, ` yarn docs:dev `进入开发模式,` yarn docs:build` 静态构建 9 | 10 | HOOK-TEST 11 | -------------------------------------------------------------------------------- /docs/.vuepress/public/Images/easyswoole.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/Images/easyswoole.png -------------------------------------------------------------------------------- /docs/.vuepress/public/bdtj.js: -------------------------------------------------------------------------------- 1 | //百度统计 2 | var _hmt = _hmt || []; 3 | (function() { 4 | var hm = document.createElement("script"); 5 | hm.src = "https://hm.baidu.com/hm.js?4c8d895ff3b25bddb6fa4185c8651cc3"; 6 | var s = document.getElementsByTagName("script")[0]; 7 | s.parentNode.insertBefore(hm, s); 8 | })(); 9 | -------------------------------------------------------------------------------- /docs/.vuepress/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/favicon.ico -------------------------------------------------------------------------------- /docs/.vuepress/public/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -e ./composer.json ]; 3 | then 4 | echo "composer.json already exist\n"; 5 | exit 1 6 | fi 7 | 8 | echo "{}" > composer.json 9 | 10 | composer config repo.packagist composer https://mirrors.aliyun.com/composer/; 11 | composer require easyswoole/easyswoole=3.x; 12 | php vendor/easyswoole/easyswoole/bin/easyswoole install; 13 | php easyswoole start; 14 | -------------------------------------------------------------------------------- /docs/.vuepress/public/playVideo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | EasySwoole视频教程 8 | 9 | 10 |
11 | 12 | 13 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/authWx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/authWx.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/banner.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/ckplayer/ckplayer.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/ckplayer/ckplayer.swf -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/ckplayer/hls/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Dailymotion (http://www.dailymotion.com) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | src/remux/mp4-generator.js and src/demux/exp-golomb.js implementation in this project 16 | are derived from the HLS library for video.js (https://github.com/videojs/videojs-contrib-hls) 17 | 18 | That work is also covered by the Apache 2 License, following copyright: 19 | Copyright (c) 2013-2015 Brightcove 20 | 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 | THE SOFTWARE. 29 | -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/ckplayer/language.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | [$second] 4 | [$second] 5 | 6 | 点击播放 7 | 暂停播放 8 | 静音 9 | 恢复音量 10 | 全屏 11 | 退出全屏 12 | 上一集 13 | 下一集 14 | 点击选择清晰度 15 | 选择字幕 16 | 17 | 18 | 音量:[$volume]% 19 | 20 | [$percentage]% 21 | 22 | [$timeh]:[$timei]:[$times] 23 | 24 | 25 | [$timeh]:[$timei]:[$times] 26 | 27 | 28 | 直播中 [$liveTimeY]-[$liveTimem]-[$liveTimed] [$liveTimeh]:[$liveTimei]:[$liveTimes] 29 | 30 | 31 | 流畅 32 | 低清 33 | 标清 34 | 高清 35 | 超清 36 | 蓝光 37 | 未知 38 | 39 | 40 | 视频地址不存在 41 | 加载失败 42 | 视频格式错误 43 | 44 | 自动 45 | 默认 46 | -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/coroutine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/coroutine.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/donate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/donate.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/easyWhoops.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/easyWhoops.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/hero.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/hero.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/img1.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/img2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/img2.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/img3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/img3.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/img4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/img4.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/img5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/img5.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/img6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/img6.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/logo.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/logo@2x.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/logo@2x.psd -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/openSource/xlsWriter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/openSource/xlsWriter.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/partner/360finance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/partner/360finance.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/partner/360games.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/partner/360games.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/partner/9377games.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/partner/9377games.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/partner/LOGO.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/partner/LOGO.psd -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/partner/chandashi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/partner/chandashi.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/partner/meitu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/partner/meitu.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/partner/tencent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/partner/tencent.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/partner/wangsu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/partner/wangsu.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/partner/yuanchu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/partner/yuanchu.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/rpcDesign.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/rpcDesign.png -------------------------------------------------------------------------------- /docs/.vuepress/public/resources/wx_donate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/.vuepress/public/resources/wx_donate.png -------------------------------------------------------------------------------- /docs/.vuepress/public/wsTool/format.js: -------------------------------------------------------------------------------- 1 | JSON.format=formatJson=function(json,options){try{JSON.parse(json)}catch(err){return json}var expression;var formatted='';var pad=0;var PADDING=' ';options=options||{};options.newlineBeforeColon=(options.newlineBeforeColon===true);options.spaceAfterColon=(options.spaceAfterColon!==false);if(typeof json!=='string'){json=JSON.stringify(json)}else{json=JSON.parse(json);json=JSON.stringify(json)}reg=/([\{\}])/g;json=json.replace(reg,'\r\n$1\r\n');reg=/([\[\]])/g;json=json.replace(reg,'\r\n$1\r\n');reg=/(\,)/g;json=json.replace(reg,'$1\r\n');reg=/(\r\n\r\n)/g;json=json.replace(reg,'\r\n');reg=/\r\n\,/g;json=json.replace(reg,',');if(!options.newlineBeforeColon){reg=/\:\r\n\{/g;json=json.replace(reg,':{');reg=/\:\r\n\[/g;json=json.replace(reg,':[')}if(options.spaceAfterColon){reg=/\:/g;json=json.replace(reg,':')}(json.split('\r\n')).forEach(function(node,index){var i=0,indent=0,padding='';if(node.match(/\{$/)||node.match(/\[$/)){indent=1}else if(node.match(/\}/)||node.match(/\]/)){if(pad!==0){pad-=1}}else{indent=0}for(i=0;i";if(hljs!==undefined)data='
'+hljs.highlightAuto(formatted).value+"
";return data}; -------------------------------------------------------------------------------- /docs/.vuepress/public/wsTool/wstool.css: -------------------------------------------------------------------------------- 1 | html {font-size: 14px;} 2 | 3 | body {overflow: hidden;} 4 | 5 | pre {font-family: monospace} 6 | 7 | .monospace {font-family: monospace} 8 | 9 | .inline-flex {display: inline-flex !important} 10 | 11 | .card-body {min-height: 90vh} 12 | 13 | .slide-fade-enter-active {transition: all .3s ease} 14 | 15 | .slide-fade-leave-active {transition: all .8s cubic-bezier(1, .5, .8, 1)} 16 | 17 | .slide-fade-enter, .slide-fade-leave-to {opacity: 0;transform: translateX(10px)} 18 | 19 | .ws-alert {position: absolute;top: 2px;right: 0;left: 0;z-index: 65535;margin: auto;max-width: 550px;text-align: center} 20 | 21 | .divider {clear: both;overflow: hidden;margin: 1rem auto;height: 0} 22 | 23 | .divider-dashed {border-top: 1px dashed #ccc} 24 | 25 | ::-webkit-scrollbar-track-piece {background-color: #f8f8f8} 26 | 27 | ::-webkit-scrollbar {width: 9px;height: 9px} 28 | 29 | ::-webkit-scrollbar-thumb {min-height: 28px;background-color: #ddd;background-clip: padding-box} 30 | 31 | ::-webkit-scrollbar-thumb:hover {background-color: #bbb} 32 | 33 | .message-box {max-height: calc(100vh - 220px)} 34 | 35 | .console-box, .message-box {display: block;overflow: auto;padding: 1rem} 36 | 37 | .console-box {max-height: calc(100vh - 485px)} -------------------------------------------------------------------------------- /docs/.vuepress/theme/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extend: '@vuepress/theme-default' 3 | }; -------------------------------------------------------------------------------- /docs/.vuepress/theme/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vuepress-theme-easyswoole", 3 | "version": "1.0.0", 4 | "description": "vuepress theme for easyswoole document", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "less": "^3.10.3", 13 | "less-loader": "^5.0.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /docs/Article/degradedService.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: swoole微服务开发中常见的服务降级 3 | meta: 4 | - name: description 5 | content: swoole是一个高并发框架拓展,在微服务的架构下,如何实现服务之间的降级保护 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|swoole 微服务|swoole降级|swoole熔断|swoole框架 8 | --- 9 | 10 | # 服务熔断限流与降级 11 | 12 | 核心思想:就是做不到最好的,那就退而求其次来保障服务。 13 | 14 | ## 为什么要熔断限流 15 | 16 | 首先,我们可以明确一件事情,无论算法,与运维再怎么优化,单台服务器的承载力,都是有限的。例如在常见的游戏服务器当中,假设我们的单机可以承载10万用户的正常游戏。某天 17 | 由于市场做了推广,导致有20万的万的用户一下子涌入进来。那么在短时间内无法扩容的情况下我们该怎么办?那就是熔断限流。我们,依旧是接纳前10万名登录的用户,后面十万的用户让他们排队去。这样看起来好像依旧会让 18 | 一半的用户不高兴,但是这也是最好的选择。如果不是这样,那么可能会导致20万,也就是全部的用户没有办法拥有一个良好的体验。 19 | 20 | ## 为什么要降级 21 | 22 | 举例一个应用场景,在某游戏服务中,有个实时统计的排行榜。正常情况下,请求进来了,都是实时转发给统计服务去统计的。而有天,因为做了活动,导致压力过大,统计服务器死机,或者是由于 23 | 其他因素,导致统计服务下线了。这个时候,请求进来,那么肯定是返回了NULL数据给前端,导致用户体验很差。因此我们可以做降级服务,例如最简单的,实时统计不行了,那我拉取上一次统计的缓存结果,总可以了吧。 24 | 25 | 26 | ## 如何实现熔断 27 | 28 | 说到熔断限流,大家在日常生活中接触最多的,应该就是令牌桶限流器了。EasySwoole 有提供一个令牌桶限流器,大家可以看文档组件库那边。那正常情况下,我们服务上线前会有一个压测。根据二八原则,服务器在负载达到百分之80左右,用户响应时间控制在200ms以下的时候,我们把 29 | 此刻的用户承载量定义为最佳的承载量,因此此时,我们就把限流器的数量限制为这个最佳承载量。降级服务也是同理,当某个服务连续访问多次,出现服务不可用的时候,我们认为该服务需要降级。 30 | -------------------------------------------------------------------------------- /docs/BaseUsage/event.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 自定义事件 3 | meta: 4 | - name: description 5 | content: EasySwoole自定义事件 6 | - name: keywords 7 | content: swoole|swoole 拓展|Easyswoole 自定义事件|swoole 框架|swoole 8 | --- 9 | 10 | ## 自定义事件 11 | easyswoole中,通过Container容器可实现自定义事件功能 12 | 13 | ## 新增`App/Event/Event.php`文件 14 | ```php 15 | get($event); 35 | if (is_callable($call)){ 36 | return call_user_func($call,...$arg); 37 | }else{ 38 | return null; 39 | } 40 | } 41 | } 42 | ``` 43 | 在框架的initialize事件中进行注册事件: 44 | ```php 45 | public static function initialize() 46 | { 47 | // TODO: Implement initialize() method. 48 | date_default_timezone_set('Asia/Shanghai'); 49 | \App\Event\Event::getInstance()->set('test', function () { 50 | echo 'test event'; 51 | }); 52 | } 53 | ``` 54 | 55 | 在其他任意位置调用: 56 | ```php 57 | Event::getInstance()->hook('test'); 58 | ``` 59 | 即可触发事件 60 | -------------------------------------------------------------------------------- /docs/Components/Component/coroutineSingleton.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 协程单例 3 | meta: 4 | - name: description 5 | content: EasySwoole 协程安全 单例模式 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|协程安全|单例模式 8 | --- 9 | 10 | # 协程单例 11 | 12 | 为兼容协程环境下的单例模式安全 可以使用CoroutineSingleTon这个trait 13 | 14 | 引用方法可以参考普通Singleton trait 15 | 16 | ```php 17 | namespace EasySwoole\Component; 18 | use Swoole\Coroutine; 19 | trait CoroutineSingleTon 20 | { 21 | private static $instance = []; 22 | static function getInstance(...$args) 23 | { 24 | $cid = Coroutine::getCid(); 25 | if(!isset(self::$instance[$cid])){ 26 | self::$instance[$cid] = new static(...$args); 27 | /* 28 | * 兼容非携程环境 29 | */ 30 | if($cid > 0){ 31 | Coroutine::defer(function ()use($cid){ 32 | unset(self::$instance[$cid]); 33 | }); 34 | } 35 | } 36 | return self::$instance[$cid]; 37 | } 38 | function destroy(int $cid = null) 39 | { 40 | if($cid === null){ 41 | $cid = Coroutine::getCid(); 42 | } 43 | unset(self::$instance[$cid]); 44 | } 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /docs/Components/Component/singleton.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 单例 3 | meta: 4 | - name: description 5 | content: EasySwoole 单例模式 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|单例模式 8 | --- 9 | # 单例 10 | 单例模式确保类在全局只能有一个实例,因为它的实例是由自己保存,在类的外部也无法对该类进行实例化。 11 | 12 | ## 作用 13 | PHP的单例模式是为了避免重复创建对象带来的资源消耗。 14 | 15 | ## 用途 16 | 实际项目中像数据库查询,日志输出,全局回调,统一校验等模块。这些模块功能单一,但需要多次访问,如果能够全局唯一,多次复用会大大提升性能。 17 | 18 | ## 例子 19 | 20 | ```php 21 | 22 | namespace EasySwoole\Component; 23 | 24 | class MySingleton 25 | { 26 | use Singleton; 27 | } 28 | 29 | $mySingleton = Mysingleton::getInstance(); 30 | 31 | ``` 32 | 33 | 34 | ## 核心对象方法 35 | 36 | 核心类:EasySwoole\Component\Singleton。 37 | 38 | 获取对象 39 | 40 | * mixed $args 参数 41 | 42 | ```php 43 | static function getInstance(...$args) 44 | ``` 45 | -------------------------------------------------------------------------------- /docs/Components/Component/tableManager.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Swoole Table 3 | meta: 4 | - name: description 5 | content: EasySwoole对Swoole table进行了基础的封装用于共享内存 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|TableManager|Swoole Table 8 | --- 9 | 10 | # TableManager 11 | `EasySwoole\Component\TableManager` 12 | EasySwoole对Swoole table进行了基础的封装,用于共享内存 13 | 14 | ## 方法列表 15 | 16 | ### getInstance() 17 | 该方法用于获取TableManager管理器实例 18 | 19 | ### add($name,array $columns,$size = 1024) 20 | 该方法用于创建一个table 21 | 22 | ### get($name):?Table 23 | 该方法用于获取已经创建好的table 24 | 25 | ## 示例代码 26 | 27 | ```php 28 | TableManager::getInstance()->add( 29 | self::TABLE_NAME, 30 | [ 31 | 'currentNum'=>['type'=>Table::TYPE_INT,'size'=>2], 32 | ], 33 | 1024 34 | ); 35 | ``` 36 | 37 | 38 | ::: warning 39 | 注意事项:请勿在onRequest、OnReceive等回调位置创建swoole table,swoole table应该在服务启动前创建,比如在mainServerCreate事件中创建。 40 | ::: 41 | -------------------------------------------------------------------------------- /docs/Components/Component/waitGroup.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: waitGroup 3 | meta: 4 | - name: description 5 | content: waitGroup 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|waitGroup|swoole waitGroup 8 | --- 9 | 10 | # waitgroup 11 | 12 | 示例代码: 13 | 14 | ```php 15 | go(function (){ 16 | $ret = []; 17 | 18 | $wait = new \EasySwoole\Component\WaitGroup(); 19 | 20 | $wait->add(); 21 | go(function ()use($wait,&$ret){ 22 | \co::sleep(0.1); 23 | $ret[] = time(); 24 | $wait->done(); 25 | }); 26 | 27 | $wait->add(); 28 | go(function ()use($wait,&$ret){ 29 | \co::sleep(2); 30 | $ret[] = time(); 31 | $wait->done(); 32 | }); 33 | 34 | $wait->wait(); 35 | 36 | var_dump($ret); 37 | }); 38 | ``` 39 | -------------------------------------------------------------------------------- /docs/Components/HttpClient/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: HTTPClient 3 | meta: 4 | - name: description 5 | content: EasySwoole 协程HTTPClient组件 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|协程HTTPClient|curl组件|协程curl 8 | --- 9 | 10 | 11 | ## EasySwoole 协程HTTPClient组件 12 | 协程httpClient组件,基于swoole [异步http client客户端](https://wiki.swoole.com/wiki/page/p-http_client.html)实现,可在协程内发起http请求不被阻塞,可用于下载文件,请求api,爬虫等一系列需求当中 13 | 14 | ## 安装 15 | 16 | ```bash 17 | composer require easyswoole/http-client 18 | ``` 19 | 20 | ## 单次请求 21 | ```php 22 | post(); 26 | 27 | $test->addCookie('c1','c1')->addCookie('c2','c2'); 28 | 29 | $test->setHeader('myHeader','myHeader'); 30 | 31 | $ret = $test->postJSON(json_encode(['json'=>1])); 32 | 33 | var_dump($ret->getBody()); 34 | ``` 35 | 36 | ## 并发请求 37 | 38 | 关于Http Client的并发请求章节,我们推荐用户使用 EasySwoole组件中提供的[Csp封装](../Component/csp.md)。 39 | -------------------------------------------------------------------------------- /docs/Components/HttpClient/response.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 响应 3 | meta: 4 | - name: description 5 | content: EasySwoole 协程HTTPClient组件 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|协程HTTPClient|curl组件|协程curl|响应 8 | --- 9 | 10 | ## 响应 11 | ```php 12 | initialize(); 15 | go(function () { 16 | $client = new \EasySwoole\HttpClient\HttpClient(); 17 | $client->setUrl('http://www.baidu.com');//设置url,注意需要http和https,https 18 | $client->addCookie('a','1'); 19 | $response = $client->get(); 20 | var_dump($response->getBody());//获取响应主体 21 | var_dump($response->getErrCode());//获取错误码 22 | var_dump($response->getErrMsg());//获取错误信息 23 | var_dump($response->getStatusCode());//获取响应状态码 24 | var_dump($response->getSetCookieHeaders());//获取响应头想要设置的cookie 25 | var_dump($response->getCookies());//获取自己发送的cookie,以及响应头想要设置的cookie 26 | }); 27 | 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/Components/HttpClient/webSocket.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: WebSocket-Client 3 | meta: 4 | - name: description 5 | content: EasySwoole 协程HTTPClient组件 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|协程HTTPClient|websocket Client|websocket客户端 8 | --- 9 | # WebSocket-Client 10 | 11 | ## 请求实例: 12 | ````php 13 | upgrade('cookie1', 'cook'); 16 | $frame = new \Swoole\WebSocket\Frame(); 17 | //设置发送的消息帧 18 | $frame->data = json_encode(['action' => 'hello','content'=>['a'=>1]]); 19 | $pushResult = $client->push($frame); 20 | $recvFrame = $client->recv(); 21 | //将返回bool或一个消息帧,可自行判断 22 | var_dump($recvFrame); 23 | ```` 24 | 25 | ::: warning 26 | recv只会接收一次服务器的消息,如果需要一直接收,请增加while(1)死循环 27 | ::: 28 | 29 | -------------------------------------------------------------------------------- /docs/Components/Jwt/decode.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: JWT组件 3 | meta: 4 | - name: description 5 | content: 基于EasySwoole组件实现的json web token 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|JWT组件 8 | --- 9 | 10 | ## 解码相关方法 11 | 12 | 解码 13 | ```php 14 | public function decode(?string $raw):?JwtObject 15 | ``` 16 | 17 | 获取解码状态, 1:通过, -1:无效, -2:token过期 18 | ```php 19 | public function getStatus(): int 20 | ``` 21 | 获取加密方式 22 | ```php 23 | public function getAlg() 24 | ``` 25 | 26 | 获取用户 27 | ```php 28 | public function getAud() 29 | ``` 30 | 31 | 获取过期时间 32 | ```php 33 | public function getExp() 34 | ``` 35 | 36 | 获取发布时间 37 | ```php 38 | public function getIat() 39 | ``` 40 | 41 | 获取发行人 42 | ```php 43 | public function getIss(): string 44 | ``` 45 | 46 | 获取jwt-id 47 | ```php 48 | public function getJti() 49 | ``` 50 | 51 | 获取生效时间 52 | ```php 53 | public function setNbf($nbf): void 54 | ``` 55 | 56 | 获取主题 57 | ```php 58 | public function getSub() 59 | ``` 60 | 61 | 获取自定义数据 62 | ```php 63 | public function getData() 64 | ``` 65 | 66 | 获取签名 67 | ```php 68 | public function getSignature() 69 | ``` 70 | 71 | 通过key获取相关数据 72 | ```php 73 | final public function getProperty($name) 74 | ``` 75 | -------------------------------------------------------------------------------- /docs/Components/Jwt/encode.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: JWT组件 3 | meta: 4 | - name: description 5 | content: 基于EasySwoole组件实现的json web token 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|JWT组件 8 | --- 9 | 10 | ## 编码相关方法 11 | 12 | 设置加密方式,默认HMACSHA256 13 | ```php 14 | function algMethod(string $method):Jwt 15 | ``` 16 | 17 | 设置秘钥,默认Easyswoole 18 | ```php 19 | function setSecretKey(string $key):Jwt 20 | ``` 21 | 22 | 初始化一个没有附带信息的token的JwtObject 23 | ```php 24 | public function publish():JwtObject 25 | ``` 26 | 27 | 设置加密方式, 默认HMACSHA256 28 | ```php 29 | public function setAlg($alg): self 30 | ``` 31 | 32 | 设置用户 33 | ```php 34 | public function setAud($aud): self 35 | ``` 36 | 37 | 设置过期时间 38 | ```php 39 | public function setExp($exp): self 40 | ``` 41 | 42 | 设置发布时间 43 | ```php 44 | public function setIat($iat): self 45 | ``` 46 | 47 | 设置发行人 48 | ```php 49 | public function setIss(string $iss): self 50 | ``` 51 | 52 | 设置jwt-id,用于标识该jwt 53 | ```php 54 | public function setJti($jti): self 55 | ``` 56 | 57 | 在此之前不可用 58 | ```php 59 | public function setNbf($nbf): self 60 | ``` 61 | 62 | 设置主题 63 | ```php 64 | public function setSub($sub): self 65 | ``` 66 | 67 | 设置其他数据 68 | ```php 69 | public function setData($data): self 70 | ``` 71 | 72 | 获取token 73 | ```php 74 | function __toString() 75 | ``` 76 | -------------------------------------------------------------------------------- /docs/Components/Jwt/images/framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/Components/Jwt/images/framework.png -------------------------------------------------------------------------------- /docs/Components/Jwt/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: JWT组件 3 | meta: 4 | - name: description 5 | content: 基于EasySwoole组件实现的json web token 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|JWT组件 8 | --- 9 | 10 | # Jwt 11 | 12 | JSON Web Token(JWT)是目前最流行的跨域身份验证解决方案。 13 | 随着技术的发展,分布式web应用的普及,通过session管理用户登录状态成本越来越高,因此慢慢发展成为token的方式做登录身份校验,然后通过token去取redis中的缓存的用户信息,随着之后jwt的出现,校验方式更加简单便捷化,无需通过redis缓存,而是直接根据token取出保存的用户信息,以及对token可用性校验,单点登录更为简单。 14 | 15 | ::: warning 16 | [建议阅读一下](https://baijiahao.baidu.com/s?id=1608021814182894637&wfr=spider&for=pc) 17 | ::: 18 | 19 | ## Jwt架构图 20 | 21 | ![](./images/framework.png) ) 22 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/deleteMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # delete 10 | 11 | delete查询 12 | 13 | 14 | ## 传参说明 15 | 16 | 方法原型 17 | ```php 18 | function delete($tableName, $numRows = null) 19 | ``` 20 | 21 | - $tableName 表名 22 | - $numRows 可不传,若传入,删除$numRows行数据 23 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/fieldsMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # fields 10 | 11 | 主要目的是查询时标识要返回的字段值 12 | 13 | ## 指定字段 14 | 15 | ```php 16 | $builder->fields(['id','title'])->get('user_list'); 17 | ``` 18 | 19 | ## 设置别名 20 | 21 | ```php 22 | $builder->fields(['id','title as notice'])->get('user_list'); 23 | ``` 24 | 25 | ## 使用SQL函数 26 | 27 | ```php 28 | $builder->fields(['id','SUM(score)'])->get('user_list'); 29 | ``` 30 | 31 | ## 传参说明 32 | 33 | 方法原型 34 | ```php 35 | function fields($fields) 36 | ``` 37 | 38 | - $fields array|string 如果非数组时,只可传入一个字段名 39 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/getMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # get 10 | 11 | select 查询 12 | 13 | ## 查询用法 14 | 15 | 查询用户数据: 16 | 17 | ```php 18 | $builder->get("user",null,"*"); 19 | ``` 20 | ## 传参说明 21 | 22 | 方法原型 23 | ```php 24 | function get($tableName, $numRows = null, $columns = null): ?QueryBuilder 25 | ``` 26 | 27 | - $tableName 表名 28 | - $numRows 所查询的条数 29 | - $columns 需要查询的字段 30 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/getOneMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # getOne 10 | 11 | 查询一条数据 12 | 13 | ## 查询用法 14 | 15 | 查询用户数据: 16 | 17 | ```php 18 | $builder->getOne("user", "name"); 19 | ``` 20 | ## 传参说明 21 | 22 | 方法原型 23 | ```php 24 | function getOne($tableName,$columns ='*') 25 | ``` 26 | 27 | - $tableName 表名 28 | - $columns 需要查询的字段 29 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/groupbyMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # groupBy 10 | 11 | 通常用于结合合计函数,根据一个或多个列对结果集进行分组 。 12 | 13 | group方法只有一个参数,并且只能使用字符串。 14 | 15 | ## 使用 16 | 17 | ```php 18 | $builder->groupBy('is_vip')->get('getTable'); 19 | $builder->groupBy('is_vip,level')->get('getTable'); 20 | ``` 21 | 22 | 23 | ## 传参说明 24 | 25 | 方法原型 26 | ```php 27 | function groupBy($groupByField) 28 | ``` 29 | 30 | - $groupByField string 分组字段 31 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/havingMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # having 10 | 11 | 用于配合group方法完成从分组的结果中筛选(通常是聚合条件)数据。 12 | 13 | 14 | ## 使用 15 | 16 | ```php 17 | $builder->groupBy('user_id')->having('times', 3,'>')->get('getTable'); 18 | ``` 19 | 20 | 21 | ## 传参说明 22 | 23 | 方法原型 24 | ```php 25 | function having($havingProp, $havingValue = 'DBNULL', $operator = '=', $cond = 'AND') 26 | ``` 27 | 28 | - $havingProp 条件 29 | - $havingValue 值 30 | - $operator string 操作符 31 | - $cond string 连接条件 32 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/insertMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # insert 10 | 11 | 插入数据 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function insert($tableName, $insertData) 18 | ``` 19 | 20 | - $tableName 表名 21 | - $insertData 需要插入的数据 22 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/joinMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # Join 10 | 11 | join通常有下面几种类型,不同类型的join操作会影响返回的数据结果。 12 | 13 | - INNER JOIN: 等同于 JOIN(默认的JOIN类型),如果表中有至少一个匹配,则返回行 14 | - LEFT JOIN: 即使右表中没有匹配,也从左表返回所有的行 15 | - RIGHT JOIN: 即使左表中没有匹配,也从右表返回所有的行 16 | - FULL JOIN: 只要其中一个表中存在匹配,就返回行 17 | 18 | ## 基本使用 19 | 20 | ```php 21 | $builder->join('table2','table2.col1 = getTable.col2')->get('getTable'); 22 | ``` 23 | 24 | ## 指定类型 25 | 26 | ```php 27 | $builder->join('table2','table2.col1 = getTable.col2','LEFT')->get('getTable'); 28 | ``` 29 | 30 | ## 传参说明 31 | 32 | 方法原型 33 | ```php 34 | function join($joinTable, $joinCondition, $joinType = '') 35 | ``` 36 | 37 | - $joinTable 表名 38 | - $joinCondition 条件 39 | - $joinType 类型 40 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/joinOrWhereMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # joinOrWhere 10 | 11 | 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function joinOrWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=') 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/joinWhereMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # joinWhere 10 | 11 | 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function joinWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/limitMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # limit 10 | 11 | limit方法主要用于指定查询和操作的数量,特别在分页查询的时候使用较多。 12 | 13 | ## 查询数量 14 | 15 | 查询10个用户数据: 16 | 17 | ```php 18 | $builder->limit(10)->get('user_list'); 19 | ``` 20 | 21 | ## 传参说明 22 | 23 | 方法原型 24 | ```php 25 | function limit(int $one, ?int $two = null) 26 | ``` 27 | 28 | - $one 若第二个参数不传,则代表取多少条数据;若第二个参数传递,则代表从第几行开始 29 | - $two 可不传,若传递,则代表从$one开始,取$two行数据 30 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/lockInShareModeMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # LockInShareModel 10 | 11 | LockInShareModel锁定(InnoDb) 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function lockInShareMode($isLock = true) 18 | ``` 19 | 20 | - $isLock 21 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/lockTableMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # lockTable 10 | 11 | 获得表锁 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function lockTable($table) 18 | ``` 19 | 20 | - $table 表名称 21 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/onDuplicateMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # onDuplicate 10 | 11 | onDuplicate插入 12 | 13 | 14 | ## 传参说明 15 | 16 | 方法原型 17 | ```php 18 | function onDuplicate($updateColumns, $lastInsertId = null) 19 | ``` 20 | 21 | - $updateColumns 更新的列 22 | - $lastInsertId 可不传,若传入,更新$lastInsertId行数据 23 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/orHavingMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # orHaving 10 | 11 | 用于配合group方法完成从分组的结果中筛选(通常是聚合条件)数据。 12 | 13 | 14 | ## 使用 15 | 16 | ```php 17 | $builder->groupBy('user_id')->orHaving('times', 3,'>')->get('getTable'); 18 | ``` 19 | 20 | ## 等同于 21 | 22 | 23 | ```php 24 | $builder->groupBy('user_id')->having('times', 3,'>','OR')->get('getTable'); 25 | ``` 26 | 27 | ## 传参说明 28 | 29 | 方法原型 30 | ```php 31 | function orHaving($havingProp, $havingValue = 'DBNULL', $operator = '=') 32 | ``` 33 | 34 | - $havingProp 条件 35 | - $havingValue 值 36 | - $operator string 操作符 37 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/orWhereMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # orWhere 10 | 11 | 快速完成条件语句构建 12 | 13 | 下面两种方法等价 14 | 15 | ```php 16 | $builder->where('is_vip', 1)->where('id', [1,2], '=', 'OR')->get('getTable'); 17 | ``` 18 | 19 | ```php 20 | $builder->where('is_vip', 1)->orWhere('id', [1,2])->get('getTable'); 21 | ``` 22 | 23 | ## 传参说明 24 | 25 | 方法原型 26 | 27 | ```php 28 | function orWhere($whereProp, $whereValue = 'DBNULL', $operator = '=') 29 | ``` 30 | 31 | - $whereProp string 支持索引数组、kv数组、或直接传递字符串 32 | - $whereValue string 条件值 33 | - $operator string 操作符 34 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/replaceMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # replace 10 | 11 | replace插入 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function replace($tableName, $insertData) 18 | ``` 19 | 20 | - $tableName 表名 21 | - $insertData 需要插入的数据 22 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/selectForUpdateMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # selectForUpdate 10 | 11 | SELECT FOR UPDATE锁定(InnoDb) 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function selectForUpdate($isLock = true) 18 | ``` 19 | 20 | - $isLock 21 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/setLockTableModeMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # setLockTableMode 10 | 11 | 锁表模式(读/写) 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function setLockTableMode($method) 18 | ``` 19 | 20 | - $method 读/写 21 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/setPrefixMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # setPrefix 10 | 11 | 设置表前缀 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function setPrefix($prefix = '') 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/setQueryOptionMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # setQueryOption 10 | 11 | 设置查询条件 12 | 13 | ## 用法 14 | 15 | 16 | ```php 17 | $builder->setQueryOption("FOR UPDATE")->where('whereUpdate', 'whereValue')->update('updateTable', ['a' => 1], 2); 18 | ``` 19 | 20 | ## 传参说明 21 | 22 | 方法原型 23 | ```php 24 | function setQueryOption($options) 25 | ``` 26 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/unionMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # union 10 | 11 | 构建UNION语句 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function union($cond, $isUnionAll = false) 18 | ``` 19 | 20 | - $cond 条件 21 | - $isUnionAll 22 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/unlockTableMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # unlockTable 10 | 11 | 释放表锁 12 | 13 | ## 传参说明 14 | 15 | 方法原型 16 | ```php 17 | function unlockTable() 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/updateMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # update 10 | 11 | update更新 12 | 13 | 14 | ## 传参说明 15 | 16 | 方法原型 17 | ```php 18 | function update($tableName, $tableData, $numRows = null) 19 | ``` 20 | 21 | - $tableName 表名 22 | - $tableData 更新的数据 23 | - $numRows 可不传,若传入,更新$numRows行数据 24 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/whereMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # where 10 | 11 | 快速完成条件语句构建。where方法的参数支持字符串和数组。 12 | 13 | ## 普通查询+ 14 | 15 | ```php 16 | $builder->where('col1', 2)->get('getTable'); 17 | ``` 18 | 19 | ## 字符串语句 20 | 21 | 可以使用字符串语句构建比较复杂的条件 22 | 23 | ```php 24 | // 生成大概语句:where status = 1 AND (id > 10 or id < 2) 25 | $builder->where('status', 1)->where(' (id > 10 or id <2) ')->get('getTable'); 26 | ``` 27 | 28 | ## 特殊操作符 29 | 30 | ```php 31 | $builder->where('id', [1,2,3], 'IN')->get('getTable'); 32 | ``` 33 | 34 | ```php 35 | $builder->where('age', 12, '>')->get('getTable'); 36 | ``` 37 | 38 | ## 连接条件 39 | 40 | ### orWhere 41 | 42 | ```php 43 | $builder->where('is_vip', 1)->where('id', [1,2], '=', 'OR')->get('getTable'); 44 | ``` 45 | 46 | ```php 47 | $builder->where('is_vip', 1)->orWhere('id', [1,2])->get('getTable'); 48 | ``` 49 | 50 | ## 传参说明 51 | 52 | 方法原型 53 | 54 | ```php 55 | function where($whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') 56 | ``` 57 | 58 | - $whereProp string 支持索引数组、kv数组、或直接传递字符串 59 | - $whereValue string 条件值 60 | - $operator string 操作符 61 | - $cond string 连接条件 62 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/Chain/withTotalCountMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # withTotalCount 10 | 11 | 统计结果行数 12 | 13 | ## 查询用法 14 | 15 | 查询用户行数: 16 | 17 | ```php 18 | $builder->withTotalCount()->get("user",null,"*"); 19 | ``` 20 | ## 传参说明 21 | 22 | 方法原型 23 | ```php 24 | function withTotalCount(): QueryBuilder 25 | ``` 26 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/builder.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # 查询构造器 10 | 11 | QueryBuilder是一个SQL构造器,用来构造prepare sql。例如: 12 | 13 | ```php 14 | use EasySwoole\Mysqli\QueryBuilder; 15 | 16 | $builder = new QueryBuilder(); 17 | 18 | //执行条件构造逻辑 19 | $builder->where('col1',2)->get('my_table'); 20 | 21 | //获取最后的查询参数 22 | echo $builder->getLastQueryOptions(); 23 | 24 | //获取子查询 25 | echo $builder->getSubQuery(); 26 | 27 | 28 | //获取上次条件构造的预处理sql语句 29 | echo $builder->getLastPrepareQuery(); 30 | // SELECT * FROM whereGet WHERE col1 = ? 31 | 32 | //获取上次条件构造的预处理sql语句所以需要的绑定参数 33 | echo $builder->getLastBindParams(); 34 | //[2] 35 | 36 | //获取上次条件构造的sql语句 37 | echo $builder->getLastQuery(); 38 | //SELECT * FROM whereGet WHERE col1 = 2 39 | 40 | // 获取最后插入的insert_id 使用客户端从swoole mysql获取 41 | $client->mysqlClient()->insert_id 42 | ``` 43 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/delete.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # 删除数据 10 | 11 | ## LIMIT DELETE 12 | ```php 13 | $client->queryBuilder()->delete('user_list', 3); 14 | ``` 15 | 16 | ## WHERE DELETE 17 | 18 | ```php 19 | $client->queryBuilder()->where('whereUpdate', 'whereValue')->delete('user_list'); 20 | ``` 21 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/insert.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # 添加数据 10 | 11 | ## INSERT INTO 12 | 13 | ```php 14 | $client->queryBuilder()->insert('insertTable', ['a' => 1, 'b' => "b"]); 15 | ``` 16 | 17 | ## REPLACE INTO 18 | 19 | ```php 20 | $builder->replace('replaceTable', ['a' => 1]); 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/install.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # Mysqli 10 | 11 | ## 安装 12 | 13 | ```php 14 | composer require easyswoole/mysqli 15 | ``` 16 | 17 | ## Client 用法 18 | ```php 19 | $config = new \EasySwoole\Mysqli\Config([ 20 | 'host' => '', 21 | 'port' => 3300, 22 | 'user' => '', 23 | 'password' => '', 24 | 'database' => '', 25 | 'timeout' => 5, 26 | 'charset' => 'utf8mb4', 27 | ]); 28 | 29 | $client = new \EasySwoole\Mysqli\Client($config); 30 | 31 | go(function ()use($client){ 32 | //构建sql 33 | $client->queryBuilder()->get('user_list'); 34 | //执行sql 35 | var_dump($client->execBuilder()); 36 | }); 37 | ``` 38 | 39 | ::: danger 40 | 需要调用execBuilder()才会执行 41 | ::: 42 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/query.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # 查询数据 10 | 11 | ## 基本查询 12 | 13 | 用id查询一条用户数据: 14 | 15 | ```php 16 | $client->queryBuilder()->where('id', 1)->getOne('user_list'); 17 | ``` 18 | 19 | 查询多条数据: 20 | 21 | ```php 22 | $client->queryBuilder()->where('is_vip', 1)->get('user_list'); 23 | ``` 24 | 25 | ::: warning 26 | get/getOne返回值查看链式操作里的详细文档 27 | ::: 28 | 29 | 30 | ::: tip 提醒 31 | 在使用 `get` 和 `getOne` 等操作方法前可以任意使用链式操作方法 32 | ::: 33 | -------------------------------------------------------------------------------- /docs/Components/Mysqli/update.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli组件 3 | meta: 4 | - name: description 5 | content: Easyswoole Mysqli库,旨在方便用户以面向对象的形式进行数据库调用的一个库。并且为Orm组件等高级用法提供了基础支持 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # 更新数据 10 | 11 | ## WHERE UPDATE 12 | 13 | ```php 14 | $client->queryBuilder()->where('whereUpdate', 'whereValue')->update('updateTable', ['a' => 1]); 15 | ``` 16 | 17 | ## LIMIT UPDATE 18 | 19 | ```php 20 | $client->queryBuilder()->update('updateTable', ['a' => 1], 5); 21 | ``` 22 | 23 | ## 快捷更新 24 | 25 | ```php 26 | $client->queryBuilder() 27 | ->where('whereUpdate', 'whereValue') 28 | ->update('updateTable', [ 29 | 'age' => QueryBuilder::inc(1), 30 | 'number' => QueryBuilder::dec(3), 31 | ]); 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /docs/Components/Orm/Associat/preWithQuery.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ORM with 预查询 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|ORM with 预查询 8 | --- 9 | 10 | # 关联预查询 11 | 12 | 在普通关联中,我们在Model类文件中定义了关系后,即可快速关联查询数据。 13 | 14 | 但在此时仍然需要我们手动获取该关联名才会执行。 15 | 16 | 预查询提供了一种主数据查询后,马上自动查询关联数据的用法。 17 | 18 | orm版本需要`>= 1.2.0` 19 | 20 | ## with方法 21 | 22 | with方法传入一个数组,内容为已经在类文件中定义好的关联名 23 | 24 | ```php 25 | $res = Model::create()->with(['user_list', 'user_store'])->get(1); 26 | 27 | var_dump($res); // 此时已经有user_list,user_sotre两个关联字段的数据,不再需要先手动调用一次。 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/Components/Orm/DefineModel/specifyConnectionName.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 指定连接名 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|指定连接名 8 | --- 9 | 10 | 11 | # 指定连接名 12 | 13 | 从 [配置信息注册](/Components/Orm/configurationRegister) 章节,我们已经知道了,在注册配置信息的时候,可以给这份配置指定一个`连接名` 14 | 15 | 16 | 可以通过模型类自定义属性 `connectionName` 来指定使用的连接配置,默认为 `default` 17 | 18 | 19 | 假设已经通过 配置信息注册 章节注册了一个 `read` 连接名的配置 20 | 21 | 那么我们可以在Model中定义指定``` read ```连接名 22 | 23 | ```php 24 | Class AdminModel extends \EasySwoole\ORM\AbstractModel 25 | { 26 | protected $connectionName = 'read'; 27 | } 28 | ``` 29 | 30 | 31 | 可以继续查看 [读写分离](/Components/Orm/readWriteSeparation) 章节,进一步查看如何使用不同数据库配置。 32 | -------------------------------------------------------------------------------- /docs/Components/Orm/DefineModel/timestamp.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 时间戳 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|指定连接名 8 | --- 9 | 10 | # 时间戳 11 | 12 | 在ORM组件版本 `>= 1.0.18` 后,增加自动时间戳特性支持。 13 | 14 | 用于:自动写入创建和更新的时间字段。 15 | 16 | - 在插入数据的时候,自动设置插入时间为当前, 17 | - 在更新数据的时候,自动设置更新时间为当前。 18 | 19 | # 使用方式 20 | 21 | ```php 22 | use \EasySwoole\ORM\AbstractModel ; 23 | 24 | Class AdminModel extends AbstractModel 25 | { 26 | // 都是非必选的,默认值看文档下面说明 27 | protected $autoTimeStamp = true; 28 | protected $createTime = 'create_at'; 29 | protected $updateTime = 'update_at'; 30 | } 31 | ``` 32 | 33 | 34 | ## autoTimeStamp 35 | 36 | 是否开启自动时间戳,默认值 `false` 37 | 38 | 可选值: 39 | 40 | - true 字段默认为int类型 储存时间戳 41 | - int 字段为int类型 储存时间戳 42 | - datetime 字段为datetime类型 Y-m-d H:i:s 43 | 44 | ## createTime 45 | 46 | `数据创建时间` 字段名,默认值 `create_time` 47 | 48 | 可选值 49 | 50 | - 任意字符串,对应为表中要储存创建时间的字段名 51 | - false,不处理创建时间字段 52 | 53 | 54 | ## updateTime 55 | 56 | `数据更新时间` 字段名,默认值 `update_time` 57 | 58 | 可选值 59 | 60 | - 任意字符串,对应为表中要储存创建时间的字段名 61 | - false,不处理更新时间字段 62 | -------------------------------------------------------------------------------- /docs/Components/Orm/add.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 新增 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|新增 8 | --- 9 | 10 | # 新增 11 | 12 | 要往数据库新增一条记录,先创建新模型实例,给实例设置属性,然后调用 save 方法: 13 | 14 | ```php 15 | $model = new UserModel(); 16 | // 不同设置值的方式 17 | $model->setAttr('id', 7); 18 | $model->name = 'name'; 19 | $model['name'] = 'name'; 20 | 21 | $res = $model->save(); 22 | var_dump($res); // 返回自增id 或者主键的值 失败则返回null 23 | ``` 24 | 在这个示例中,我们将 `id` 和 `name` 赋值给了 UserModel 模型实例的 `id` 和 `name` 属性。当调用 `save` 方法时,将会插入一条新记录 25 | 26 | 27 | ### 数组赋值 28 | 29 | 可以传入数组`[字段名=>字段值]` 再调用 `save` 方法保存 30 | 31 | ```php 32 | $model = UserModel::create([ 33 | 'name' => 'siam', 34 | 'age' => 21, 35 | ]); 36 | 37 | $res = $model->save(); 38 | ``` 39 | 40 | ```php 41 | // data($data, $setter = true) 42 | // 第二个参数 可以决定是否要调用修改器(如果要设置的话 下面的文档有说明) 43 | $user = UserModel::create()->data([ 44 | 'name' => 'siam', 45 | 'age' => 21, 46 | ], false)->save(); 47 | ``` 48 | -------------------------------------------------------------------------------- /docs/Components/Orm/aggregation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 聚合 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|聚合 8 | --- 9 | 10 | 11 | # 聚合 12 | 13 | ORM 还提供了各种聚合方法,比如 count, max,min, avg,还有 sum。你可以在构造查询后调用任何方法: 14 | 15 | ## max 16 | 17 | ```php 18 | $max = TestUserListModel::create()->max('age'); 19 | ``` 20 | 21 | ## min 22 | 23 | ```php 24 | $min = TestUserListModel::create()->min('age'); 25 | ``` 26 | 27 | ## count 28 | 29 | ```php 30 | // count 不必传字段名 31 | $count = TestUserListModel::create()->count(); 32 | ``` 33 | 34 | ## avg 35 | 36 | ```php 37 | $avg = TestUserListModel::create()->avg('age'); 38 | ``` 39 | 40 | ## sum 41 | 42 | ```php 43 | $sum = TestUserListModel::create()->sum('age'); 44 | ``` 45 | 46 | -------------------------------------------------------------------------------- /docs/Components/Orm/customSqlExecution.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 自定义SQL执行 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|自定义SQL执行 8 | --- 9 | 10 | 11 | # 自定义SQL执行 12 | 13 | 有时候你可能需要在查询中使用原生表达式。你可以使用 `QueryBuilder` 构造一个原生 `SQL` 表达式 14 | 15 | ORM 内部依赖的是 `mysqli` 组件的`QueryBuilder` 16 | 17 | ```php 18 | use EasySwoole\Mysqli\QueryBuilder; 19 | 20 | $queryBuild = new QueryBuilder(); 21 | // 支持参数绑定 第二个参数非必传 22 | $queryBuild->raw("select * from test where name = ?", ['siam']); 23 | // $queryBuild->raw("select * from test where name = 'siam'"); 24 | 25 | // 第二个参数 raw 指定true,表示执行原生sql 26 | // 第三个参数 connectionName 指定使用的连接名,默认 default 27 | $data = DbManager::getInstance()->query($queryBuild, true, 'default'); 28 | 29 | ``` 30 | 31 | 通过Model执行 32 | ```php 33 | // 需要注意的是,这里的sql语句仅仅是示例 34 | // 正确推荐的做法应该仍然是查询Model类对应的表,得到表结构字段的数据 35 | $data = Model::create()->get(function ($queryBuild){ 36 | $queryBuild->raw("show tables"); 37 | }); 38 | ``` 39 | 40 | ::: warning 41 | 原生 SQL 表达式将会被当做字符串注入到查询中,因此你应该小心使用,避免创建 SQL 注入的漏洞。 42 | ::: 43 | -------------------------------------------------------------------------------- /docs/Components/Orm/defineModel.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 定义模型 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | 10 | # 定义模型 11 | 定义一个模型基础的模型,只需要创建一个类,并且继承`EasySwoole\ORM\AbstractModel`即可 12 | 13 | ```php 14 | 15 | get(1); 20 | $user->destroy(); 21 | ``` 22 | 23 | ## 通过 主键 24 | 25 | ```php 26 | $res = UserModel::create()->destroy(1); //通过直接指定主键(如果存在) 27 | $res = UserModel::create()->destroy('2,4,5');//指定多个参数每个参数为不同主键 28 | $res = UserModel::create()->destroy([3, 7]);//数组指定多个主键 29 | ``` 30 | 31 | ### 通过 where 条件 32 | 33 | ```php 34 | $res = UserModel::create()->destroy(['age' => 21]);//数组指定 where 条件结果来删除 35 | $res = UserModel::create()->destroy(function (QueryBuilder $builder) { 36 | $builder->where('id', 1); 37 | }); 38 | ``` 39 | 40 | ## 删除全表数据 41 | 42 | 如果你需要清空表,你可以使用 destroy 方法传入 (null,true),它将删除所有行 43 | 44 | ```php 45 | $res = UserModel::create()->destroy(null,true); 46 | ``` 47 | -------------------------------------------------------------------------------- /docs/Components/Orm/getter.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 获取器 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|获取器 8 | --- 9 | 10 | 11 | # 获取器 12 | 13 | 获取器的作用是在获取数据的字段值后自动进行处理 14 | 15 | 若要定义一个获取器,则须在你的模型上创建一个 「`get` 字段名 `Attr`」 方法。 16 | 17 | 要访问的字段的获取器方法需使用「小驼峰」来命名。在这个例子中,我们将为 `status` 属性定义一个访问器。 18 | 19 | ::: tip 20 | 数据表的字段会在使用获取器时自动转换为驼峰法访问 21 | ::: 22 | 23 | 当 ORM实例 尝试获取 status 的值时,将会自动调用此访问器: 24 | ```php 25 | class UserModel extends AbstractModel 26 | { 27 | /** 28 | * $value mixed 是原值 29 | * $data array 是当前model所有的值 30 | */ 31 | protected function getStatusAttr($value, $data) 32 | { 33 | $status = [-1=>'删除',0=>'禁用',1=>'正常',2=>'待审核']; 34 | return $status[$value]; 35 | } 36 | } 37 | ``` 38 | 39 | 获取器还可以定义数据表中不存在的字段,例如: 40 | ```php 41 | protected function getEasyswooleAttr($value,$data) 42 | { 43 | return 'Easyswoole用户-'.$data['id']; 44 | } 45 | ``` 46 | 那么在外部我们就可以使用这个easyswoole字段了 47 | ```php 48 | $res = UserModel::create()->get(4); 49 | var_dump($res->easyswoole); 50 | ``` 51 | 52 | 53 | -------------------------------------------------------------------------------- /docs/Components/Orm/install.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ORM组件 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # ORM 10 | Easyswoole提供的一个全新协程安全的ORM封装。 11 | # 安装 12 | 13 | 依赖关系 14 | 15 | - swoole `>= 4.4.8` 16 | - Easyswoole `>=3.3.2` 17 | - mysqli > `2.x` 18 | 19 | ```php 20 | composer require easyswoole/orm 21 | ``` 22 | 23 | ::: tip 24 | Orm的功能是依赖于mysqli 2.x组件的,update的$data参数将会传递给mysqli构造sql。 25 | 26 | 所以我们可以直接使用大部分mysqli的功能 27 | ::: 28 | -------------------------------------------------------------------------------- /docs/Components/Orm/invoke.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Orm Invoke 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|Orm Invoke 8 | --- 9 | 10 | # orm invoke 11 | 12 | 在高并发情况下,资源浪费的占用时间越短越好,可以提高程序的服务效率。 13 | 14 | 在ORM默认情况下是使用defer方法获取pool内的连接资源,并在协程退出时自动归还,在此情况下,在带来便利的同时,会造成不必要资源的浪费。 15 | 16 | 我们可以使用invoke方式,让ORM查询结束后马上归还资源,可以提高资源的利用率。 17 | 18 | ```php 19 | $user = DbManager::getInstance()->invoke(function ($client){ 20 | 21 | $testUserModel = Model::invoke($client); 22 | $testUserModel->state = 1; 23 | $testUserModel->name = 'Siam'; 24 | $testUserModel->age = 18; 25 | $testUserModel->addTime = date('Y-m-d H:i:s'); 26 | 27 | $data = $testUserModel->save(); 28 | return $data; 29 | }); 30 | 31 | var_dump($user); 32 | ``` 33 | 34 | ::: tip 35 | 旧版本的invoke没有return值,请更新orm版本。 36 | ::: 37 | 38 | ## 方法支持 39 | 40 | 在此种模式下,主要有两个方法需要讲解。 41 | 42 | - DbManager下的invoke方法 (从连接池内获取一个连接,并在闭包完成时归还连接) 43 | - Model的invoke方法 (注入客户端连接,不再从连接池内defer获取) 44 | 45 | ## invoke中调试sql 46 | 47 | 版本>=1.2.12提供特性 48 | 49 | 关于lastQueryResult、lastQuery返回内容,请查看章节`模型执行结果`、`最后执行语句` 50 | 51 | ```php 52 | $client->lastQueryResult(); 53 | $client->lastQuery(); 54 | ``` 55 | 56 | -------------------------------------------------------------------------------- /docs/Components/Orm/lastQuery.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Orm 最后执行语句 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|Orm Invoke 8 | --- 9 | # 最后执行语句 10 | 11 | 当model执行一个语句之后,会将该次执行的语句保存到`$model->lastQuery()`中: 12 | 13 | ```php 14 | all()); 18 | //打印最后执行的`EasySwoole\Mysqli\QueryBuilder` 对象 19 | var_dump($model->lastQuery()); 20 | //打印最后执行的sql语句 21 | var_dump($model->lastQuery()->getLastQuery()); 22 | 23 | 24 | // 以下快速获取方式在版本>=1.2.12后提供 25 | DbManager::getInstance()->getConnection()->defer()->lastQuery(); 26 | AdminModel::defer()->lastQuery(); 27 | 28 | ``` 29 | 30 | ::: warning 31 | $model->lastQuery() 返回的是query对象,具体文档可查看:[查询构造器](../Mysqli/builder.md) 文档 32 | ::: 33 | -------------------------------------------------------------------------------- /docs/Components/Orm/lastResult.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Orm 执行结果 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|Orm Invoke 8 | --- 9 | # 执行结果 10 | 11 | 当model执行一个语句之后,会将该次执行的结果保存到`$model->lastQueryResult()`中,该方法将返回一个`EasySwoole\ORM\Db\Result`对象 12 | 13 | ```php 14 | all(); 17 | //获取查询结果对象 18 | $lastResult = $model->lastQueryResult(); 19 | //获取查询数据总数,查询时需要调用`withTotalCount`才可以使用该方法 20 | var_dump($lastResult->getTotalCount()); 21 | //获得最后插入的id 22 | var_dump($lastResult->getLastInsertId()); 23 | //获取执行影响的数据条数 update,delete等方法使用 24 | var_dump($lastResult->getAffectedRows()); 25 | //获取错误code 26 | var_dump($lastResult->getLastErrorNo()); 27 | //获取错误消息 28 | var_dump($lastResult->getLastError()); 29 | //获取执行mysql返回的结果 30 | var_dump($lastResult->getResult()); 31 | 32 | // 以下内容在版本>=1.2.2后提供 33 | 34 | // 获取结果中的第一条 35 | var_dump($lastResult->getResultOne()); 36 | // 获取结果中某列 37 | var_dump($lastResult->getResultColumn(string $column)); 38 | // 获取结果中某列的第一条数据 39 | var_dump($lastResult->getResultScalar(string $column)); 40 | // 以某一个字段名为key 返回结果数组 41 | var_dump($lastResult->getResultIndexBy(string $column)); 42 | 43 | // 以下快速获取方式在版本>=1.2.12后提供 44 | DbManager::getInstance()->getConnection()->defer()->lastQueryResult(); 45 | AdminModel::defer()->lastQueryResult(); 46 | ``` 47 | 48 | :::warning 49 | 当$model执行get,all,save等类似方法出错时,可通过调用getLastError方法获取错误消息用于调试 50 | ::: 51 | -------------------------------------------------------------------------------- /docs/Components/Orm/modifier.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 修改器 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|修改器 8 | --- 9 | 10 | # 修改器 11 | 12 | 修改器的作用是在模型实例修改字段赋值时自动进行处理 13 | 14 | 若要定义一个修改器,则须在你的模型上创建一个 「`set` 字段名 `Attr`」 方法。 15 | 16 | 要定义的修改器方法需使用「小驼峰」来命名。在这个例子中,我们将为 `name` 属性定义一个修改器。 17 | 18 | ::: tip 19 | 数据表的字段会在使用获取器时自动转换为驼峰法访问 20 | ::: 21 | 22 | 当 模型实例 尝试修改 `name`字段的值时,将会自动调用此修改器: 23 | 24 | ```php 25 | class UserModel extends AbstractModel 26 | { 27 | /** 28 | * $value mixed 是原值 29 | * $data array 是当前model所有的值 30 | */ 31 | protected function setNameAttr($value, $data) 32 | { 33 | return $value."_加一个统一后缀"; 34 | } 35 | } 36 | ``` 37 | 如下代码在设置保存的时候将会被修改器处理后保存 38 | ```php 39 | $model = new UserModel([ 40 | 'name' => 'siam', 41 | 'age' => 21, 42 | ]); 43 | $model->save(); 44 | //name 存入后值为: siam_加一个统一后缀 45 | ``` 46 | -------------------------------------------------------------------------------- /docs/Components/Orm/popularScienceConcept.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 科普概念 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM 8 | --- 9 | # ORM 简介 10 | 11 | 对象关系映射(Object Relational Mapping,简称ORM)是描述代码控制和数据库之间映射的元数据,将面向对象语言程序中的对象自动关联到相应数据库中。本质上就是将数数据库沟通操作以一种复杂组合操作形式转换到另外一种方便理解便捷操作的对象形式。 12 | 每个数据库表都有一个对应的「模型」用该模型的实例化一个新的对象来与该表交互。你可以通过模型查询数据表中的数据,以及在数据表中插入新记录。 13 | -------------------------------------------------------------------------------- /docs/Components/Orm/quickQuery.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 快捷查询 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|快捷查询 8 | --- 9 | 10 | 11 | # 快捷查询 12 | 13 | 依赖关系 14 | - mysqli >=2.1.2 15 | - ORM >= 1.2.5 16 | 17 | 查询单行指定字段值 18 | - val(string $column) 19 | - scalar(?string $column = null) 20 | 21 | 查询多行指定字段值 22 | - column(?string $column = null) 23 | - indexBy(string $column) 24 | 25 | ## 返回值说明 26 | - `val` 当存在该行数据并字段存在时,返回该字段值。 27 | 字段不存在时,返回该行数据数组。 28 | 该行不存在时,返回`null` 29 | 30 | - `scalar` 当符合条件数据存在时,返回首条数据字段值。 31 | 当符合条件不存在时,返回空数组。 32 | 当不传参数时,默认返回主键值。 33 | 34 | - `column` 返回该字段值的数组。 35 | 当参数不传时,默认返回主键数组。 36 | 37 | - `indexBy`返回以指定字段为Key的数据数组。 38 | 39 | ## 示例 40 | 41 | ```php 42 | 43 | // val 直接返回某一行的某一列 44 | $res = UserModel::create()->val('loginName'); 45 | var_dump($res); 46 | 47 | // column 快速查询结果的某一列 48 | $res = UserModel::create()->column('loginName'); 49 | var_dump($res); 50 | 51 | // scalar 快速查询结果的某一列的第一条数据 52 | $res = UserModel::create()->scalar('loginName'); 53 | var_dump($res); 54 | 55 | // indexBy 以某个字段名的数据返回结果数组 56 | $res = UserModel::create()->indexBy('loginName'); 57 | var_dump($res); 58 | 59 | ``` 60 | -------------------------------------------------------------------------------- /docs/Components/Orm/readWriteSeparation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 读写分离 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件,读写分离 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|swoole 读写分离 8 | --- 9 | 10 | 11 | # 读写分离 12 | 13 | 14 | ## 注册读写链接配置信息 15 | 16 | 首先,我们需要按照 [配置信息注册](./configuration_register) 注册 读 / 写 两个链接的信息 17 | 18 | 主要代码大概如下 19 | 20 | ```php 21 | DbManager::getInstance()->addConnection($con, 'read'); 22 | DbManager::getInstance()->addConnection($con2, 'write'); 23 | ``` 24 | 25 | ## 指定使用链接 26 | 27 | 有两种方式可以使用 可以根据自己的需求选择 28 | 29 | 主要利用AbstractModel提供的`connection()`方法 30 | 31 | ```php 32 | function connection(string $name, bool $isTemp = false) 33 | ``` 34 | 35 | ::: tip 提示 36 | 第二个参数需要传入为true,表示临时使用,否则该认定为固定使用
建议只在临时使用时设置该方式,如果要固定使用则从Model类文件中定义。 37 | ::: 38 | 39 | ### Model继承定义 40 | 41 | ```php 42 | class Test extends AbstractModel{ 43 | /** 这里因为不是使用默认的配置链接名 所以需要指定 */ 44 | protected $connectionName = 'write'; 45 | 46 | /** get 方法使用读链接 */ 47 | public function get($where = null, bool $returnAsArray) 48 | { 49 | $this->connection('read', true); 50 | return parent::get($where, $returnAsArray); 51 | } 52 | } 53 | ``` 54 | 55 | ### 外部使用 56 | 57 | ```php 58 | Test::create()->connection('read',true)->all(); 59 | ``` 60 | -------------------------------------------------------------------------------- /docs/Components/Orm/specialQuery.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 特殊条件查询 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM组件, 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli协程客户端|swoole ORM|查询|特殊sql语句 8 | --- 9 | 10 | # 特殊条件查询 11 | 12 | ## find_in_set 13 | 14 | 生成条件 find_in_set(1, name) 15 | 16 | ? 代表参数绑定,可以直接写明条件,第二个参数不传递即可,但需要注意防范注入风险 17 | 18 | ```php 19 | $data = Model::create()->where("find_in_set(?, name)", [1])->get(); 20 | ``` 21 | 22 | ## 复杂where or 23 | 24 | ```php 25 | // 生成大概语句:where status = 1 AND (id > 10 or id < 2) 26 | Model::create()->where('status', 1)->where(' (id > 10 or id <2) ')->get(); 27 | ``` 28 | -------------------------------------------------------------------------------- /docs/Components/Pool/config.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: EasySwoole通用连接池 3 | meta: 4 | - name: description 5 | content: EasySwoole通用连接池,协程连接池,easyswoole连接池 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|连接池|swoole 连接池|通用连接池 8 | --- 9 | 10 | ## 连接池配置 11 | 在实例化一个连接池对象时,需要传入一个连接池配置对象`EasySwoole\Pool\Config`,该对象的属性如下: 12 | 13 | | 配置项 | 默认值 | 说明 | 备注 | 14 | |:-------------------|:--------|:------------------------|:--------------------------------------------------------------------------------------| 15 | | $intervalCheckTime | 30*1000 | 定时器执行频率 | 用于定时执行连接池对象回收,创建操作 | 16 | | $maxIdleTime | 15 | 连接池对象最大闲置时间(秒) | 超过这个时间未使用的对象将会被定时器回收 | 17 | | $maxObjectNum | 20 | 连接池最大数量 | 每个进程最多会创建$maxObjectNum连接池对象,如果对象都在使用,则会返回空,或者等待连接空闲 | 18 | | $minObjectNum | 5 | 连接池最小数量(热启动) | 当连接池对象总数低于$minObjectNum时,会自动创建连接,保持连接的活跃性,让控制器能够尽快的获取连接 | 19 | | $getObjectTimeout | 3.0 | 获取连接池的超时时间 | 当连接池为空时,会等待$getObjectTimeout秒,如果期间有连接空闲,则会返回连接对象,否则返回null | 20 | | $extraConf | | 额外配置信息 | 在实例化连接池前,可把一些额外配置放到这里,例如数据库配置信息,redis配置等等 | 21 | 22 | -------------------------------------------------------------------------------- /docs/Components/Queue/install.md: -------------------------------------------------------------------------------- 1 | # Queue介绍 2 | 3 | Easyswoole封装实现了一个轻量级的队列,默认以Redis作为队列驱动器。 4 | 5 | 可以自己实现一个队列驱动来实现用kafka或者启动方式的队列存储。 6 | 7 | 从上可知,Queue并不是一个单独使用的组件,它更像一个对不同驱动的队列进行统一封装的门面组件。 8 | 9 | # 开始安装 10 | 11 | ``` 12 | composer require easyswoole/queue 13 | ``` 14 | 15 | # 使用流程 16 | 17 | - 注册队列驱动器 18 | - 设置消费进程 19 | - 生产者投递任务 20 | 21 | ## Redis 驱动示例 22 | 23 | ```php 24 | use EasySwoole\Redis\Config\RedisConfig; 25 | use EasySwoole\RedisPool\RedisPool; 26 | use EasySwoole\Queue\Driver\Redis; 27 | use EasySwoole\Queue\Queue; 28 | use EasySwoole\Queue\Job; 29 | 30 | $config = new RedisConfig([ 31 | 'host'=>'127.0.0.1' 32 | ]); 33 | $redis = new RedisPool($config); 34 | 35 | $driver = new Redis($redis); 36 | $queue = new Queue($driver); 37 | 38 | go(function ()use($queue){ 39 | while (1){ 40 | $job = new Job(); 41 | $job->setJobData(time()); 42 | $id = $queue->producer()->push($job); 43 | var_dump('job create for Id :'.$id); 44 | \co::sleep(3); 45 | } 46 | }); 47 | 48 | go(function ()use($queue){ 49 | $queue->consumer()->listen(function (Job $job){ 50 | var_dump($job->toArray()); 51 | }); 52 | }); 53 | ``` -------------------------------------------------------------------------------- /docs/Components/Redis/connection.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: redis协程客户端 3 | meta: 4 | - name: description 5 | content: redis协程客户端,由swoole 协程client实现,覆盖了redis 99%的方法 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole redis| Swoole redis协程客户端|swoole Redis|redis协程 8 | --- 9 | ## 连接方法 10 | 连接方法包括一些auth,echo,ping,类似的方法,列表如下: 11 | 12 | 13 | 14 | | 方法名称 | 参数 | 说明 | 备注 | 15 | |:-----------|:----------|:----------|:----| 16 | | connect | $timeout | 连接 | | 17 | | disconnect | | 断开连接 | | 18 | | auth | $password | auth认证 | | 19 | | echo | $str | echo | | 20 | | ping | | ping | | 21 | | select | $db | 选择数据库 | | 22 | 23 | 24 | ## 实例 25 | ```php 26 | go(function () { 27 | $redis = new \EasySwoole\Redis\Redis(new \EasySwoole\Redis\Config\RedisConfig([ 28 | 'host' => '127.0.0.1', 29 | 'port' => '6379', 30 | 'auth' => 'easyswoole', 31 | 'serialize' => \EasySwoole\Redis\Config\RedisConfig::SERIALIZE_NONE 32 | ])); 33 | $data = $redis->connect(); 34 | var_dump($data); 35 | $data = $redis->auth('easyswoole'); 36 | var_dump($data); 37 | $data = $redis->echo('test echo'); 38 | var_dump($data); 39 | $data = $redis->ping(); 40 | var_dump($data); 41 | $data = $redis->select(1); 42 | var_dump($data); 43 | $redis->disconnect(); 44 | }); 45 | ``` 46 | -------------------------------------------------------------------------------- /docs/Components/Redis/error.md: -------------------------------------------------------------------------------- 1 | ## redis错误处理 2 | redis组件根据错误的级别,区分了2种错误信息 3 | 4 | ### 异常 5 | 当redis连接失败,无法和redis服务通信时,将会抛出` EasySwoole\Redis\Exception\RedisException` 异常,例如配置错误: 6 | ``` 7 | PHP Fatal error: Uncaught EasySwoole\Redis\Exception\RedisException: connect to redis host 127.0.0.1:6379 fail after retry 4 times in /www/easyswoole/tioncico_redis/src/Redis.php:2866 8 | Stack trace: 9 | #0 /www/easyswoole/tioncico_redis/src/Redis.php(579): EasySwoole\Redis\Redis->sendCommand(Array) 10 | #1 /www/easyswoole/tioncico_redis/tests/test.php(17): EasySwoole\Redis\Redis->get('a') 11 | #2 {main} 12 | thrown in /www/easyswoole/tioncico_redis/src/Redis.php on line 2866 13 | 14 | ``` 15 | 我们只需要接管该异常即可: 16 | ```php 17 | go(function () { 18 | 19 | $redisConfig = new \EasySwoole\Redis\Config\RedisConfig(); 20 | $redisConfig->setAuth('easyswoole'); 21 | $redis = new \EasySwoole\Redis\Redis($redisConfig); 22 | try{ 23 | 24 | $data = $redis->rawCommand(['set','a','1','1']);//多了一个参数,redis将会报语法错误 25 | var_dump($data); 26 | 27 | }catch (\EasySwoole\Redis\Exception\RedisException $exception){ 28 | 29 | var_dump($exception->getMessage()); 30 | var_dump($exception->getRedisErrorCode()); 31 | var_dump($exception->getRedisErrorMsg()); 32 | } 33 | }); 34 | ``` -------------------------------------------------------------------------------- /docs/Components/Redis/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: redis协程客户端 3 | meta: 4 | - name: description 5 | content: redis协程客户端,由swoole 协程client实现,覆盖了redis 99%的方法 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole redis| Swoole redis协程客户端|swoole Redis|redis协程 8 | --- 9 | ## redis协程客户端 10 | 虽然swoole有着自带的协程客户端,但是在生产环境中我们发现了一些问题: 11 | swoole的redis客户端并没有完全支持redis的全部命令,比如geo搜索,还有事务,特别是集群模式的redis,swoole客户端并不支持。为此,我们决定用swoole的tcp客户端实现一个完整版的redis客户端。 12 | 13 | 14 | ## 支持方法 15 | 目前,该redis客户端组件,已经支持除去脚本外的所有方法(目前支持了178个方法): 16 | 17 | - 连接方法(connection) 18 | - 集群方法(cluster) 19 | - geohash 20 | - 哈希(hash) 21 | - 键(keys) 22 | - 列表(lists) 23 | - 订阅/发布(pub/sub) 24 | - 服务器(server) 25 | - 字符串(string) 26 | - 有序集合(sorted sets) 27 | - 集合 (sets) 28 | - 事务 (transaction) 29 | - 管道实现 (pipe) 30 | 31 | > 由于redis的命令较多,可能漏掉1,2个命令 32 | 33 | 34 | -------------------------------------------------------------------------------- /docs/Components/Redis/rawCommand.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: redis协程客户端 3 | meta: 4 | - name: description 5 | content: redis协程客户端,由swoole 协程client实现,覆盖了redis 99%的方法 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole redis| Swoole redis协程客户端|swoole Redis|redis协程 8 | --- 9 | ## 自定义命令 10 | redis客户端提供了`rawCommand`方法以供使用自定义命令: 11 | 12 | ```php 13 | $data = $redis->rawCommand(['set','a','1']); 14 | var_dump($data); 15 | $data = $redis->rawCommand(['get','a']); 16 | var_dump($data); 17 | $redis->del('a'); 18 | ``` 19 | rawCommand将返回一个`EasySwoole\Redis\Response`对象 20 | ``` 21 | object(EasySwoole\Redis\Response)#8 (4) { 22 | ["status":protected]=> 23 | int(0) 24 | ["data":protected]=> 25 | string(2) "OK" 26 | ["msg":protected]=> 27 | NULL 28 | ["errorType":protected]=> 29 | NULL 30 | } 31 | object(EasySwoole\Redis\Response)#9 (4) { 32 | ["status":protected]=> 33 | int(0) 34 | ["data":protected]=> 35 | string(1) "1" 36 | ["msg":protected]=> 37 | NULL 38 | ["errorType":protected]=> 39 | NULL 40 | } 41 | ``` 42 | -------------------------------------------------------------------------------- /docs/Components/Redis/redis.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: redis协程客户端 3 | meta: 4 | - name: description 5 | content: redis协程客户端,由swoole 协程client实现,覆盖了redis 99%的方法 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole redis| Swoole redis协程客户端|swoole Redis|redis协程 8 | --- 9 | # Redis单机客户端 10 | 11 | 示例: 12 | ```php 13 | '127.0.0.1', 17 | 'port' => '6379', 18 | 'auth' => 'easyswoole', 19 | 'serialize' => \EasySwoole\Redis\Config\RedisConfig::SERIALIZE_NONE 20 | ])); 21 | var_dump($redis->set('a',1)); 22 | var_dump($redis->get('a')); 23 | }); 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/Components/Smtp/content.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Smtp 3 | meta: 4 | - name: description 5 | content: Easyswoole提供了一个发送邮件组件,电子邮件是—种用电子手段提供信息交换的通信方式,是互联网应用最广的服务。电子邮件几乎是每个web应用程序不可或缺的,无论是时事通讯还是订单确认。本组件采用swoole协程客户端实现了电子邮件的发送。 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|Smtp 8 | --- 9 | 10 | # 邮件内容 11 | 12 | 支持文本和html两种类型 13 | 14 | ## 文本 15 | 16 | #### 示例 17 | ```php 18 | $mimeBean = new \EasySwoole\Smtp\Message\Text(); 19 | $mimeBean->setSubject('Hello Word!'); 20 | $mimeBean->setBody('

Hello Word

'); 21 | ``` 22 | 23 | #### 效果 24 | ![](./image/text.png) 25 | 26 | ## Html 27 | ```php 28 | $mimeBean = new \EasySwoole\Smtp\Message\Html(); 29 | $mimeBean->setSubject('Hello Word!'); 30 | $mimeBean->setBody('

Hello Word

'); 31 | ``` 32 | 33 | #### 效果 34 | ![](./image/html.png) 35 | 36 | ## 附件 37 | ```php 38 | $mimeBean = new \EasySwoole\Smtp\Message\Text(); 39 | //$mimeBean = new \EasySwoole\Smtp\Message\Html(); 40 | 41 | ... 42 | 43 | // 创建附件 44 | $createAttachment = Attach::create('./test.txt'); 45 | 46 | // 添加附件 47 | $mimeBean->addAttachment($createAttachment); 48 | 49 | ... 50 | ``` 51 | 52 | -------------------------------------------------------------------------------- /docs/Components/Smtp/contentconfig.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Smtp 3 | meta: 4 | - name: description 5 | content: Easyswoole提供了一个发送邮件组件,电子邮件是—种用电子手段提供信息交换的通信方式,是互联网应用最广的服务。电子邮件几乎是每个web应用程序不可或缺的,无论是时事通讯还是订单确认。本组件采用swoole协程客户端实现了电子邮件的发送。 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|Smtp 8 | --- 9 | 10 | # 内容配置 11 | 12 | ## set 13 | 14 | 设置协议版本 15 | ```php 16 | public function setMimeVersion($mimeVersion): void 17 | ``` 18 | 19 | 设置contentType 20 | ```php 21 | public function setContentType($contentType): void 22 | ``` 23 | 24 | 设置字符 25 | ```php 26 | public function setCharset($charset): void 27 | ``` 28 | 29 | 设置编码 30 | ```php 31 | public function setContentTransferEncoding($contentTransferEncoding): void 32 | ```` 33 | 34 | 设置主题 35 | ```php 36 | public function setSubject($subject): void 37 | ``` 38 | 39 | 设置邮件内容 40 | ```php 41 | public function setBody($body): void 42 | ```` 43 | 44 | 添加附件 45 | ```php 46 | public function addAttachment($attachment) 47 | ``` 48 | 49 | ## get 50 | 51 | 获取协议版本 52 | ```php 53 | public function getMimeVersion() 54 | ``` 55 | 56 | 获取contenttype 57 | ```php 58 | public function getContentType() 59 | ``` 60 | 61 | 获取字符 62 | ```php 63 | public function getCharset() 64 | ``` 65 | 66 | 获取编码 67 | ```php 68 | public function getContentTransferEncoding() 69 | ``` 70 | 71 | 获取主题 72 | ```php 73 | public function getSubject() 74 | ``` 75 | 76 | 获取邮件内容 77 | ```php 78 | public function getBody() 79 | ``` 80 | 81 | 获取附件 82 | ```php 83 | public function getAttachments() 84 | ``` 85 | -------------------------------------------------------------------------------- /docs/Components/Smtp/image/html.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/Components/Smtp/image/html.png -------------------------------------------------------------------------------- /docs/Components/Smtp/image/text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/Components/Smtp/image/text.png -------------------------------------------------------------------------------- /docs/Components/Smtp/smtp.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Smtp 3 | meta: 4 | - name: description 5 | content: Easyswoole提供了一个发送邮件组件,电子邮件是—种用电子手段提供信息交换的通信方式,是互联网应用最广的服务。电子邮件几乎是每个web应用程序不可或缺的,无论是时事通讯还是订单确认。本组件采用swoole协程客户端实现了电子邮件的发送。 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|Smtp 8 | --- 9 | 10 | # Smtp 11 | 12 | 电子邮件是—种用电子手段提供信息交换的通信方式,是互联网应用最广的服务。电子邮件几乎是每个web应用程序不可或缺的,无论是时事通讯还是订单确认。本库采用swoole协程客户端实现了电子邮件的发送。 13 | 14 | ## 安装 15 | ```php 16 | composer require easyswoole/smtp 17 | ``` 18 | ## 使用 19 | ```php 20 | use EasySwoole\Smtp\Mailer; 21 | use EasySwoole\Smtp\MailerConfig; 22 | use EasySwoole\Smtp\Message\Html; 23 | use EasySwoole\Smtp\Message\Attach; 24 | // 必须用go 25 | go(function (){ 26 | $config = new MailerConfig(); 27 | $config->setServer('smtp.163.com'); 28 | $config->setSsl(false); 29 | $config->setUsername('huizhang'); 30 | $config->setPassword('*******'); 31 | $config->setMailFrom('xx@163.com'); 32 | $config->setTimeout(10);//设置客户端连接超时时间 33 | $config->setMaxPackage(1024*1024*5);//设置包发送的大小:5M 34 | 35 | //设置文本或者html格式 36 | $mimeBean = new Html(); 37 | $mimeBean->setSubject('Hello Word!'); 38 | $mimeBean->setBody('

Hello Word

'); 39 | 40 | //添加附件 41 | $mimeBean->addAttachment(Attach::create('./test.txt')); 42 | 43 | $mailer = new Mailer($config); 44 | $mailer->sendTo('xx@qq.com', $mimeBean); 45 | }); 46 | 47 | ``` 48 | -------------------------------------------------------------------------------- /docs/Components/Sundries/hash.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Hash 3 | meta: 4 | - name: description 5 | content: 用于快速处理哈希密码以及数据完整性校验等场景。 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|组件库|杂项工具|Hash 8 | --- 9 | 10 | # Hash 11 | 12 | 13 | 14 | ## 用途 15 | 16 | 用于快速处理哈希密码以及数据完整性校验等场景 17 | 18 | 19 | 20 | ## 核心对象类 21 | 22 | 实现该组件功能需加载核心类: 23 | 24 | ```php 25 | EasySwoole\Utility\Hash 26 | ``` 27 | 28 | 29 | 30 | ## 核心对象方法 31 | 32 | 33 | 34 | #### makePasswordHash 35 | 36 | 从一个明文值生产哈希 37 | 38 | - mixed $value 需要生产哈希的原文 39 | - mixed $cost 递归的层数 40 | 41 | ```php 42 | static function makePasswordHash($value, $cost = 10) 43 | ``` 44 | 45 | 46 | 47 | #### validatePasswordHash 48 | 49 | 校验明文值与哈希是否匹配 50 | 51 | - mixed $value 原文 52 | - mixed $cost 哈希加密文 53 | 54 | ```php 55 | static function validatePasswordHash($value, $hashValue) 56 | ``` 57 | 58 | 59 | 60 | ## 如何使用 61 | 62 | ```php 63 | 81 | * int(1532127766018) 82 | * ["dataCenterID"]=> 83 | * int(1) 84 | * ["workerID"]=> 85 | * int(1) 86 | * ["sequence"]=> 87 | * int(0) 88 | * } 89 | */ 90 | ``` 91 | 92 | -------------------------------------------------------------------------------- /docs/Components/VerifyCode/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 验证码 3 | meta: 4 | - name: description 5 | content: EasySwoole验证码组件,可自定义生成二维码图形或者base64等编码. 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|验证码|swoole验证码 8 | --- 9 | # EasySwoole 验证码组件 10 | 11 | ::: warning 12 | 仓库地址: [验证码组件](https://github.com/easy-swoole/verifyCode) 13 | ::: 14 | 15 | 16 | EasySwoole提供了独立的 `验证码组件` ,几行代码即可实现输出一个验证码 17 | 18 | ## composer 安装 19 | ```php 20 | composer require easyswoole/verifycode=3.x 21 | ``` 22 | 23 | ### 示例: 24 | ```php 25 | response()->withHeader('Content-Type','image/png'); 44 | $this->response()->write($code->DrawCode()->getImageByte()); 45 | } 46 | 47 | function getBase64(){ 48 | $config = new Conf(); 49 | $code = new \EasySwoole\VerifyCode\VerifyCode($config); 50 | $this->response()->write($code->DrawCode()->getImageBase64()); 51 | } 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /docs/Components/apollo.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: apollo配置中心 3 | meta: 4 | - name: description 5 | content: EasySwoole apollo配置中心 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|apollo 8 | --- 9 | # apollo配置中心 10 | EasySwoole实现了对apollo数据中心的支持.可根据该组件,进行同步配置 11 | # apollo 12 | 13 | ## 安装 14 | 15 | ``` 16 | composer require easyswoole/apollo 17 | ``` 18 | 19 | ## 使用 20 | 21 | ```php 22 | go(function (){ 23 | //配置apollo服务器信息 24 | $server = new \EasySwoole\Apollo\Server([ 25 | 'server'=>'http://106.12.25.204:8080', 26 | 'appId'=>'easyswoole' 27 | ]); 28 | //创建apollo客户端 29 | $apollo = new \EasySwoole\Apollo\Apollo($server); 30 | //第一次同步 31 | var_dump( $apollo->sync('mysql')); 32 | //第二次同步,若服务端没有改变,那么返回的结果,isModify标记为fasle,并带有lastReleaseKey 33 | var_dump( $apollo->sync('mysql')); 34 | }); 35 | ``` 36 | 37 | 38 | ::: warning 39 | 可以在进程中起一个定时器,实现自动定时更新 40 | ::: 41 | 42 | -------------------------------------------------------------------------------- /docs/Components/phpunit.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: EasySwoole利用phpunit进行单元测试 3 | meta: 4 | - name: description 5 | content: EasySwoole利用phpunit进行单元测试 swoole单元测试 协程环境单元测试 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole 单元测试|swoole 单元测试|swoole phpunit 8 | --- 9 | 10 | # Phpunit 11 | 12 | Easyswoole/Phpunit 是对 Phpunit 的协程定制化封装,主要为解决自动协程化入口的问题。并屏蔽了Swoole ExitException 13 | 14 | ## 安装 15 | ``` 16 | composer require easyswoole/phpunit 17 | ``` 18 | ## 使用 19 | 执行 20 | ``` 21 | ./vendor/bin/co-phpunit tests 22 | ``` 23 | 24 | 25 | ::: warning 26 | tests为你写的测试文件的目录,可以自定义 27 | ::: 28 | 29 | ## 预处理 30 | ```php 31 | /* 32 | * 允许自动的执行一些初始化操作,只初始化一次 33 | */ 34 | if(file_exists(getcwd().'/phpunit.php')){ 35 | require_once getcwd().'/phpunit.php'; 36 | } 37 | ``` 38 | 39 | easyswoole/phpunit 支持在项目目录下定义一个phpunit.php,用户可以在该文件下进行统一的测试前预处理 40 | 41 | 其他测试与phpunit一致 42 | 43 | ## EasySwoole中使用 44 | 自3.2.5版本的Easyswoole起,已经默认集成了 easyswoole/phpunit 组件。命令行下执行: 45 | ``` 46 | php easyswoole phpunit tests 47 | ``` 48 | 49 | 即可进行测试,若部分测试需要Http或者tcp等服务,可以先以启动easyswoole并进入守护模式,再进行测试 50 | 51 | 52 | 53 | ::: warning 54 | tests为你写的测试文件的目录,可以自定义 55 | ::: 56 | -------------------------------------------------------------------------------- /docs/Core/event.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 全局事件 3 | meta: 4 | - name: description 5 | content: 全局事件 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole|swoole|全局事件 8 | --- 9 | # 全局事件 10 | 11 | 参考不同的Demo分支event写法: [demo分支](https://github.com/easy-swoole/demo/branches) 12 | EasySwoole有五个全局事件,全部位于框架安装后生成的EasySwooleEvent.php中。 13 | 14 | - initialize 框架初始化事件 15 | - mainServerCreate 主服务创建事件 16 | - onRequest Http请求事件 17 | - afterRequest Http响应后事件 18 | -------------------------------------------------------------------------------- /docs/Core/event/afterRequest.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: afterRequest 3 | meta: 4 | - name: description 5 | content: swoole事件,请求方法结束后执行 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole|swoole事件|afterRequest 8 | --- 9 | ## 请求方法结束后执行 10 | 11 | ### 函数原型 12 | ```php 13 | public static function afterRequest(Request $request, Response $response): void 14 | { 15 | } 16 | ``` 17 | 18 | ## 示例 19 | 可在该事件中做trace 进行请求的追踪监视,以及获取此次的响应内容 20 | ```php 21 | public static function afterRequest(Request $request, Response $response): void 22 | { 23 | TrackerManager::getInstance()->getTracker()->endPoint('request'); 24 | 25 | $responseMsg = $response->getBody()->__toString(); 26 | Logger::getInstance()->console("响应内容:".$responseMsg); 27 | // 响应状态码: 28 | // var_dump($response->getStatusCode()); 29 | 30 | 31 | // tracker结束,结束之后,能看到中途设置的参数,调用栈的运行情况 32 | TrackerManager::getInstance()->closeTracker(); 33 | // TODO: Implement afterAction() method. 34 | } 35 | ``` 36 | 37 | -------------------------------------------------------------------------------- /docs/Core/event/initialize.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: initialize 3 | meta: 4 | - name: description 5 | content: 框架初始化事件 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole|swoole|initialize 8 | --- 9 | # 框架初始化事件 10 | 11 | ## 函数原型 12 | 13 | ```php 14 | public static function initialize(): void 15 | { 16 | } 17 | ``` 18 | 19 | ## 已完成工作 20 | 21 | 在执行框架初始化事件时,EasySwoole已经完成的工作有: 22 | 23 | - 全局常量EASYSWOOLE_ROOT的定义 24 | - 系统默认Log/Temp目录的定义 25 | 26 | 27 | ## 可处理内容 28 | 29 | 在该事件中,可以进行一些系统常量的更改和全局配置,例如: 30 | 31 | - 修改并创建系统默认Log/Temp目录。 32 | - 引入用户自定义配置 33 | - 注册 数据库,redis 连接池 34 | - trace链追踪器注册 35 | 36 | ## 启动前调用协程API 37 | ```php 38 | use Swoole\Coroutine\Scheduler; 39 | $scheduler = new Scheduler(); 40 | $scheduler->add(function() { 41 | /* 调用协程API */ 42 | }); 43 | $scheduler->start(); 44 | //清除全部定时器 45 | \Swoole\Timer::clearAll(); 46 | ``` 47 | -------------------------------------------------------------------------------- /docs/Core/event/onReceive.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: onReceive 3 | meta: 4 | - name: description 5 | content: 当接收到客户端数据时,会触发此事件 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole|swoole|onReceive 8 | --- 9 | ## onReceive 10 | 11 | 主服务为SERVER时有效,当接收到客户端数据时,会触发此事件 12 | 13 | ###函数原型 14 | ```php 15 | public static function onReceive(\swoole_server $server, int $fd, int $reactor_id, string $data): void 16 | { 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/Core/event/onRequest.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: onRequest 3 | meta: 4 | - name: description 5 | content: 收到请求事件 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole|swoole|onRequest 8 | --- 9 | ## 收到请求事件 10 | 11 | ```php 12 | public static function onRequest(Request $request, Response $response): bool 13 | ``` 14 | 15 | 当EasySwoole收到任何的HTTP请求时,均会执行该事件。该事件可以对HTTP请求全局拦截。 16 | 17 | ```php 18 | getRequestParam('code'); 24 | if (0/*empty($code)验证失败*/){ 25 | $data = Array( 26 | "code" => Status::CODE_BAD_REQUEST, 27 | "result" => [], 28 | "msg" => '验证失败' 29 | ); 30 | $response->write(json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); 31 | $response->withHeader('Content-type', 'application/json;charset=utf-8'); 32 | $response->withStatus(Status::CODE_BAD_REQUEST); 33 | return false; 34 | } 35 | 36 | return true; 37 | } 38 | ``` 39 | 40 | 41 | ::: warning 42 | 若在该事件中,执行 $response->end(),则该次请求不会进入路由匹配阶段。 43 | ::: 44 | 45 | -------------------------------------------------------------------------------- /docs/Core/lifecycle.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 框架生命周期 3 | meta: 4 | - name: description 5 | content: 框架生命周期 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole|swoole|框架生命周期 8 | --- 9 | ## 框架生命周期 10 | 11 | ![lifecycle](./lifecycle.png) 12 | -------------------------------------------------------------------------------- /docs/Core/lifecycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/Core/lifecycle.png -------------------------------------------------------------------------------- /docs/Core/other.md: -------------------------------------------------------------------------------- 1 | # 其他 待补充 -------------------------------------------------------------------------------- /docs/En/Components/Component/coroutineSingleton.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Coroutine Singleton 3 | meta: 4 | - name: description 5 | content: EasySwoole Coroutine security Coroutine Singleton 6 | - name: keywords 7 | content: swoole|swoole expand|swoole frame|easyswoole|Coroutine security|Coroutine Singleton 8 | --- 9 | 10 | # Coroutine Singleton 11 | 12 | For the security of singleton mode under the compatible cooperation environment, coroutinesingleton can be used 13 | 14 | Reference method can refer to common Singleton trait 15 | 16 | ```php 17 | namespace EasySwoole\Component; 18 | use Swoole\Coroutine; 19 | trait CoroutineSingleTon 20 | { 21 | private static $instance = []; 22 | static function getInstance(...$args) 23 | { 24 | $cid = Coroutine::getCid(); 25 | if(!isset(self::$instance[$cid])){ 26 | self::$instance[$cid] = new static(...$args); 27 | /* 28 | * 兼容非携程环境 29 | */ 30 | if($cid > 0){ 31 | Coroutine::defer(function ()use($cid){ 32 | unset(self::$instance[$cid]); 33 | }); 34 | } 35 | } 36 | return self::$instance[$cid]; 37 | } 38 | function destroy(int $cid = null) 39 | { 40 | if($cid === null){ 41 | $cid = Coroutine::getCid(); 42 | } 43 | unset(self::$instance[$cid]); 44 | } 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /docs/En/Components/Component/singleton.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Single case 3 | meta: 4 | - name: description 5 | content: EasySwoole singleton mode 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|Easyswoole|singleton mode 8 | --- 9 | # Single case 10 | The singleton pattern ensures that a class can only have one instance globally, because its instances are saved by itself and cannot be instantiated outside of the class. 11 | 12 | ## Effect 13 | PHP's singleton mode is to avoid the resource consumption caused by repeated creation of objects. 14 | 15 | ## Use 16 | The actual project is like a database query, log output, global callback, unified check and other modules. These modules have a single function, but require multiple accesses. If they are globally unique, multiple reuses will greatly improve performance. 17 | 18 | ## Example 19 | 20 | ```php 21 | 22 | namespace EasySwoole\Component; 23 | 24 | class MySingleton 25 | { 26 | use Singleton; 27 | } 28 | 29 | $mySingleton = Mysingleton::getInstance(); 30 | 31 | ``` 32 | 33 | 34 | ## Core object method 35 | 36 | Core class: EasySwoole\Component\Singleton。 37 | 38 | Get object 39 | 40 | * mixed $args parameter 41 | 42 | ```php 43 | static function getInstance(...$args) 44 | ``` 45 | -------------------------------------------------------------------------------- /docs/En/Components/Component/tableManager.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Swoole Table 3 | meta: 4 | - name: description 5 | content: EasySwoole has a basic package for Swoole table for shared memory 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|easyswoole|TableManager|Swoole Table 8 | --- 9 | 10 | # TableManager 11 | `EasySwoole\Component\TableManager` 12 | EasySwoole has a basic package for Swoole table for shared memory 13 | 14 | ## Method list 15 | 16 | ### getInstance() 17 | This method is used to get the TableManager manager instance. 18 | 19 | ### add($name,array $columns,$size = 1024) 20 | This method is used to create a table 21 | 22 | ### get($name):?Table 23 | This method is used to get the table that has been created. 24 | 25 | ## Sample code 26 | 27 | ```php 28 | TableManager::getInstance()->add( 29 | self::TABLE_NAME, 30 | [ 31 | 'currentNum'=>['type'=>Table::TYPE_INT,'size'=>2], 32 | ], 33 | 1024 34 | ); 35 | ``` 36 | 37 | 38 | ::: warning 39 | Note: Do not create a swoole table in callback locations such as onRequest, OnReceive, etc. The swoole table should be created before the service is started, for example in the mainServerCreate event. 40 | ::: 41 | -------------------------------------------------------------------------------- /docs/En/Components/Component/waitGroup.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: waitGroup 3 | meta: 4 | - name: description 5 | content: waitGroup 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|easyswoole|waitGroup|swoole waitGroup 8 | --- 9 | 10 | # waitgroup 11 | 12 | Sample code: 13 | 14 | ```php 15 | go(function (){ 16 | $ret = []; 17 | 18 | $wait = new \EasySwoole\Component\WaitGroup(); 19 | 20 | $wait->add(); 21 | go(function ()use($wait,&$ret){ 22 | \co::sleep(0.1); 23 | $ret[] = time(); 24 | $wait->done(); 25 | }); 26 | 27 | $wait->add(); 28 | go(function ()use($wait,&$ret){ 29 | \co::sleep(2); 30 | $ret[] = time(); 31 | $wait->done(); 32 | }); 33 | 34 | $wait->wait(); 35 | 36 | var_dump($ret); 37 | }); 38 | ``` 39 | -------------------------------------------------------------------------------- /docs/En/Components/HttpClient/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: HTTPClient 3 | meta: 4 | - name: description 5 | content: EasySwoole coroutine HTTPClient component 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|Easyswoole| coroutine HTTPClient|curl component|coroutine curl 8 | --- 9 | 10 | 11 | ## EasySwoole coroutine HTTPClient component 12 | The coroutine httpClient component, based on the swoole [asynchronous http client client] (https://wiki.swoole.com/wiki/page/p-http_client.html), can initiate http requests in the coroutine without being blocked. In downloading files, requesting apis, crawlers, etc. 13 | 14 | ## installation 15 | 16 | ```bash 17 | composer require easyswoole/http-client 18 | ``` 19 | 20 | ## Single request 21 | ```php 22 | post(); 26 | 27 | $test->addCookie('c1','c1')->addCookie('c2','c2'); 28 | 29 | $test->setHeader('myHeader','myHeader'); 30 | 31 | $ret = $test->postJSON(json_encode(['json'=>1])); 32 | 33 | var_dump($ret->getBody()); 34 | ``` 35 | 36 | ## Concurrent request 37 | 38 | For the Http Client Concurrency Request section, we recommend that users use the [Csp Package] (../Component/csp.md) provided in the EasySwoole component. 39 | -------------------------------------------------------------------------------- /docs/En/Components/HttpClient/response.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Response 3 | meta: 4 | - name: description 5 | content: EasySwoole Coroutine HTTPClient component 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|easyswoole|Coroutine HTTPClient|Curl component|coroutine curl|Response 8 | --- 9 | 10 | ## Response 11 | ```php 12 | initialize(); 15 | go(function () { 16 | $client = new \EasySwoole\HttpClient\HttpClient(); 17 | $client->setUrl('http://www.baidu.com');//Set the url, note that you need http and https, https 18 | $client->addCookie('a','1'); 19 | $response = $client->get(); 20 | var_dump($response->getBody());//Get response body 21 | var_dump($response->getErrCode());//Get the error code 22 | var_dump($response->getErrMsg());//Get error message 23 | var_dump($response->getStatusCode());//Get response status code 24 | var_dump($response->getSetCookieHeaders());//Get the cookie that the response header wants to set 25 | var_dump($response->getCookies());//Get the cookie you sent yourself and the cookie that the response header wants to set 26 | }); 27 | 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/En/Components/HttpClient/webSocket.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: WebSocket-Client 3 | meta: 4 | - name: description 5 | content: EasySwoole Coroutine HTTPClient component 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|easyswoole|Coroutine HTTPClient|websocket Client|Websocket client 8 | --- 9 | # WebSocket-Client 10 | 11 | ## Request instance: 12 | ````php 13 | upgrade('cookie1', 'cook'); 16 | $frame = new \Swoole\WebSocket\Frame(); 17 | //Set the sent message frame 18 | $frame->data = json_encode(['action' => 'hello','content'=>['a'=>1]]); 19 | $pushResult = $client->push($frame); 20 | $recvFrame = $client->recv(); 21 | //Will return bool or a message frame, you can judge 22 | var_dump($recvFrame); 23 | ```` 24 | 25 | ::: warning 26 | Recv will only receive the server's message once, if you need to receive it all the time, please increase the while(1) infinite loop 27 | ::: 28 | 29 | -------------------------------------------------------------------------------- /docs/En/Components/Jwt/decode.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: component 3 | meta: 4 | - name: description 5 | content: JSON based on easysoole component web token 6 | - name: keywords 7 | content: swoole|swoole Expand|swoole frame|easyswoole|JWT component 8 | --- 9 | 10 | ## Decoding correlation method 11 | 12 | Decode 13 | ```php 14 | public function decode(?string $raw):?JwtObject 15 | ``` 16 | 17 | Get decoding status, 1: pass, - 1: invalid, - 2: token expired 18 | ```php 19 | public function getStatus(): int 20 | ``` 21 | 22 | Get encryption method 23 | ```php 24 | public function getAlg() 25 | ``` 26 | 27 | get user 28 | ```php 29 | public function getAud() 30 | ``` 31 | 32 | Get expiration time 33 | ```php 34 | public function getExp() 35 | ``` 36 | 37 | Get release time 38 | ```php 39 | public function getIat() 40 | ``` 41 | 42 | Get issuer 43 | ```php 44 | public function getIss(): string 45 | ``` 46 | 47 | Get jwt-id 48 | ```php 49 | public function getJti() 50 | ``` 51 | 52 | Get effective time 53 | ```php 54 | public function setNbf($nbf): void 55 | ``` 56 | 57 | Get topic 58 | ```php 59 | public function getSub() 60 | ``` 61 | 62 | Get custom data 63 | ```php 64 | public function getData() 65 | ``` 66 | 67 | Get signature 68 | ```php 69 | public function getSignature() 70 | ``` 71 | 72 | Get relevant data through key 73 | ```php 74 | final public function getProperty($name) 75 | ``` 76 | -------------------------------------------------------------------------------- /docs/En/Components/Jwt/images/framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/En/Components/Jwt/images/framework.png -------------------------------------------------------------------------------- /docs/En/Components/Jwt/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: component 3 | meta: 4 | - name: description 5 | content: JSON based on easysoole component web token 6 | - name: keywords 7 | content: swoole|swoole Expand|swoole frame|easyswoole|JWT component 8 | --- 9 | 10 | # Jwt 11 | 12 | JSON Web Token(JWT)Is the most popular cross domain authentication solution. 13 | With the development of technology and the popularization of distributed web applications, the cost of managing users' login status through session is getting higher and higher, so it gradually develops into a token method to do login identity verification, and then through token to get the cached user information in redis. With the emergence of JWT, the verification method is more simple and convenient, without redis caching, but directly based on the token Single sign on is easier to save user information and check the availability of token. 14 | 15 | ![](./images/framework.png) ) 16 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/deleteMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # delete 10 | 11 | Delete query 12 | 13 | 14 | ## Pass the instructions 15 | 16 | Method prototype 17 | ```php 18 | function delete($tableName, $numRows = null) 19 | ``` 20 | 21 | - $tableName Table Name 22 | - $numRows Can not pass, if passed, delete $numRows row data 23 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/fieldsMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # fields 10 | 11 | The main purpose is to identify the field value to be returned when querying 12 | 13 | ## Specified field 14 | 15 | ```php 16 | $builder->fields(['id','title'])->get('user_list'); 17 | ``` 18 | 19 | ## Set alias 20 | 21 | ```php 22 | $builder->fields(['id','title as notice'])->get('user_list'); 23 | ``` 24 | 25 | ## Using SQL functions 26 | 27 | ```php 28 | $builder->fields(['id','SUM(score)'])->get('user_list'); 29 | ``` 30 | 31 | ## Pass the instructions 32 | 33 | Method prototype 34 | ```php 35 | function fields($fields) 36 | ``` 37 | 38 | - $fields array|String can only pass in a field name if it is not an array 39 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/getMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # get 10 | 11 | select Inquire 12 | 13 | ## Query usage 14 | 15 | Query user data: 16 | 17 | ```php 18 | $builder->get("user",null,"*"); 19 | ``` 20 | ## Pass the instructions 21 | 22 | Method prototype 23 | ```php 24 | function get($tableName, $numRows = null, $columns = null): ?QueryBuilder 25 | ``` 26 | 27 | - $tableName Table Name 28 | - $numRows The number of queries 29 | - $columns Fields to be queried 30 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/getOneMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # getOne 10 | 11 | Query a piece of data 12 | 13 | ## Query usage 14 | 15 | Query user data: 16 | 17 | ```php 18 | $builder->getOne("user", "name"); 19 | ``` 20 | ## Pass the instructions 21 | 22 | Method prototype 23 | ```php 24 | function getOne($tableName,$columns ='*') 25 | ``` 26 | 27 | - $tableName Table Name 28 | - $columns Fields to be queried 29 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/groupbyMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # groupBy 10 | 11 | Typically used to combine aggregate functions to group result sets based on one or more columns. 12 | 13 | The group method has only one argument and can only use strings. 14 | 15 | ## Use 16 | 17 | ```php 18 | $builder->groupBy('is_vip')->get('getTable'); 19 | $builder->groupBy('is_vip,level')->get('getTable'); 20 | ``` 21 | 22 | 23 | ## Pass the instructions 24 | 25 | Method prototype 26 | ```php 27 | function groupBy($groupByField) 28 | ``` 29 | 30 | - $groupByField string Grouping field 31 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/havingMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # having 10 | 11 | Used to match the group method to filter data (usually aggregated conditions) from the results of the grouping. 12 | 13 | 14 | ## Use 15 | 16 | ```php 17 | $builder->groupBy('user_id')->having('times', 3,'>')->get('getTable'); 18 | ``` 19 | 20 | 21 | ## Pass the instructions 22 | 23 | Method prototype 24 | ```php 25 | function having($havingProp, $havingValue = 'DBNULL', $operator = '=', $cond = 'AND') 26 | ``` 27 | 28 | - `$havingProp` condition 29 | - `$havingValue` value 30 | - `$operator string` Operator 31 | - `$cond string` Connection condition 32 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/insertMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # insert 10 | 11 | Insert data 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function insert($tableName, $insertData) 18 | ``` 19 | 20 | - `$tableName` Table Name 21 | - `$insertData` Need to insert data 22 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/joinMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # Join 10 | 11 | `join` usually have the following types, and different types of `join` operations can affect the returned data results. 12 | 13 | - INNER JOIN: Equivalent to JOIN (the default JOIN type), returning rows if there is at least one match in the table 14 | - LEFT JOIN: Return all rows from the left table even if there is no match in the right table 15 | - RIGHT JOIN: Return all rows from the right table even if there is no match in the left table 16 | - FULL JOIN: Return rows as long as there is a match in one of the tables 17 | 18 | ## Basic use 19 | 20 | ```php 21 | $builder->join('table2','table2.col1 = getTable.col2')->get('getTable'); 22 | ``` 23 | 24 | ## Specified type 25 | 26 | ```php 27 | $builder->join('table2','table2.col1 = getTable.col2','LEFT')->get('getTable'); 28 | ``` 29 | 30 | ## Pass the instructions 31 | 32 | Method prototype 33 | ```php 34 | function join($joinTable, $joinCondition, $joinType = '') 35 | ``` 36 | 37 | - $joinTable Table Name 38 | - $joinCondition Condition 39 | - $joinType Type 40 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/joinOrWhereMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # joinOrWhere 10 | 11 | 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function joinOrWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=') 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/joinWhereMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # joinWhere 10 | 11 | 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function joinWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/limitMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # limit 10 | 11 | The limit method is mainly used to specify the number of queries and operations, especially when using paging queries. 12 | 13 | ## Number of queries 14 | 15 | Query 10 user data: 16 | 17 | ```php 18 | $builder->limit(10)->get('user_list'); 19 | ``` 20 | 21 | ## Pass the instructions 22 | 23 | Method prototype 24 | ```php 25 | function limit(int $one, ?int $two = null) 26 | ``` 27 | 28 | - $one If the second parameter is not passed, it means how many pieces of data are taken; if the second parameter is passed, it means starting from the first line. 29 | - $tow Can not pass, if passed, it means starting from $one, taking $tow line data 30 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/lockInShareModeMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # LockInShareModel 10 | 11 | LockInShareModel lock(InnoDb) 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function lockInShareMode($isLock = true) 18 | ``` 19 | 20 | - $isLock 21 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/lockTableMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # lockTable 10 | 11 | Obtain a table lock 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function lockTable($table) 18 | ``` 19 | 20 | - $table Table name 21 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/onDuplicateMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # onDuplicate 10 | 11 | onDuplicate insertion 12 | 13 | 14 | ## Pass the instructions 15 | 16 | Method prototype 17 | ```php 18 | function onDuplicate($updateColumns, $lastInsertId = null) 19 | ``` 20 | 21 | - $updateColumns Updated column 22 | - $lastInsertId Can not pass, if passed, update the $lastInsertId line data 23 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/orHavingMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # orHaving 10 | 11 | Used to match the group method to filter data (usually aggregated conditions) from the results of the grouping. 12 | 13 | 14 | ## Use 15 | 16 | ```php 17 | $builder->groupBy('user_id')->orHaving('times', 3,'>')->get('getTable'); 18 | ``` 19 | 20 | ## Equivalent to 21 | 22 | 23 | ```php 24 | $builder->groupBy('user_id')->having('times', 3,'>','OR')->get('getTable'); 25 | ``` 26 | 27 | ## Pass the instructions 28 | 29 | Method prototype 30 | ```php 31 | function orHaving($havingProp, $havingValue = 'DBNULL', $operator = '=') 32 | ``` 33 | 34 | - $havingProp Condition 35 | - $havingValue value 36 | - $operator string Operator 37 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/orWhereMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # orWhere 10 | 11 | Quickly complete conditional statement construction 12 | 13 | The following two methods are equivalent 14 | 15 | ```php 16 | $builder->where('is_vip', 1)->where('id', [1,2], '=', 'OR')->get('getTable'); 17 | ``` 18 | 19 | ```php 20 | $builder->where('is_vip', 1)->orWhere('id', [1,2])->get('getTable'); 21 | ``` 22 | 23 | ## Pass the instructions 24 | 25 | Method prototype 26 | 27 | ```php 28 | function orWhere($whereProp, $whereValue = 'DBNULL', $operator = '=') 29 | ``` 30 | 31 | - $whereProp string Support indexed arrays, kv arrays, or directly passed strings 32 | - $whereValue stringConditional value 33 | - $operator string Operator 34 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/replaceMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # replace 10 | 11 | Replace insert 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function replace($tableName, $insertData) 18 | ``` 19 | 20 | - $tableName Table Name 21 | - $insertData Need to insert data 22 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/selectForUpdateMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # selectForUpdate 10 | 11 | SELECT FOR UPDATE lock(InnoDb) 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function selectForUpdate($isLock = true) 18 | ``` 19 | 20 | - $isLock 21 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/setLockTableModeMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # setLockTableMode 10 | 11 | Lock table mode (read/write) 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function setLockTableMode($method) 18 | ``` 19 | 20 | - $method Read/write 21 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/setPrefixMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # setPrefix 10 | 11 | Set table prefix 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function setPrefix($prefix = '') 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/setQueryOptionMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # setQueryOption 10 | 11 | Set query conditions 12 | 13 | ## Usage 14 | 15 | 16 | ```php 17 | $builder->setQueryOption("FOR UPDATE")->where('whereUpdate', 'whereValue')->update('updateTable', ['a' => 1], 2); 18 | ``` 19 | 20 | ## Pass the instructions 21 | 22 | Method prototype 23 | ```php 24 | function setQueryOption($options) 25 | ``` 26 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/unionMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # union 10 | 11 | Build a UNION statement 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function union($cond, $isUnionAll = false) 18 | ``` 19 | 20 | - $cond Condition 21 | - $isUnionAll 22 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/unlockTableMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # unlockTable 10 | 11 | Release table lock 12 | 13 | ## Pass the instructions 14 | 15 | Method prototype 16 | ```php 17 | function unlockTable() 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/updateMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # update 10 | 11 | Update 12 | 13 | 14 | ## Pass the instructions 15 | 16 | Method prototype 17 | ```php 18 | function update($tableName, $tableData, $numRows = null) 19 | ``` 20 | 21 | - $tableName Table Name 22 | - $tableData Updated data 23 | - $numRows Can not pass, if passed, update the $numRows row data 24 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/Chain/withTotalCountMethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # withTotalCount 10 | 11 | Number of rows of statistical results 12 | 13 | ## Query usage 14 | 15 | Query the number of user lines: 16 | 17 | ```php 18 | $builder->withTotalCount()->get("user",null,"*"); 19 | ``` 20 | ## Pass the instructions 21 | 22 | Method prototype 23 | ```php 24 | function withTotalCount(): QueryBuilder 25 | ``` 26 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/builder.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # Query constructor 10 | 11 | QueryBuilder is a SQL constructor for constructing prepare sql. E.g: 12 | 13 | ```php 14 | use EasySwoole\Mysqli\QueryBuilder; 15 | 16 | $builder = new QueryBuilder(); 17 | 18 | //Execution conditional construction logic 19 | $builder->where('col1',2)->get('my_table'); 20 | 21 | //Get the last query parameter 22 | echo $builder->getLastQueryOptions(); 23 | 24 | //Get subquery 25 | echo $builder->getSubQuery(); 26 | 27 | 28 | //Get the pre-processing sql statement of the last condition construct 29 | echo $builder->getLastPrepareQuery(); 30 | // SELECT * FROM whereGet WHERE col1 = ? 31 | 32 | //Get the pre-processing sql statement of the last condition construct, so the required binding parameters 33 | echo $builder->getLastBindParams(); 34 | //[2] 35 | 36 | //Get the sql statement of the last conditional construct 37 | echo $builder->getLastQuery(); 38 | //SELECT * FROM whereGet WHERE col1 = 2 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/delete.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # Delete data 10 | 11 | ## LIMIT DELETE 12 | ```php 13 | $client->queryBuilder()->delete('user_list', 3); 14 | ``` 15 | 16 | ## WHERE DELETE 17 | 18 | ```php 19 | $client->queryBuilder()->where('whereUpdate', 'whereValue')->delete('user_list'); 20 | ``` 21 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/insert.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # Adding data 10 | 11 | ## INSERT INTO 12 | 13 | ```php 14 | $client->queryBuilder()->insert('insertTable', ['a' => 1, 'b' => "b"]); 15 | ``` 16 | 17 | ## REPLACE INTO 18 | 19 | ```php 20 | $builder->replace('replaceTable', ['a' => 1]); 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/install.md: -------------------------------------------------------------------------------- 1 | # Mysqli 2 | 3 | --- 4 | title: Mysqli component 5 | meta: 6 | - name: description 7 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 8 | - name: keywords 9 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 10 | --- 11 | 12 | 13 | ## Installation 14 | 15 | ```php 16 | composer require easyswoole/mysqli 17 | ``` 18 | 19 | ## Client usage 20 | ```php 21 | $config = new \EasySwoole\Mysqli\Config([ 22 | 'host' => '', 23 | 'port' => 3300, 24 | 'user' => '', 25 | 'password' => '', 26 | 'database' => '', 27 | 'timeout' => 5, 28 | 'charset' => 'utf8mb4', 29 | ]); 30 | 31 | $client = new \EasySwoole\Mysqli\Client($config); 32 | 33 | go(function ()use($client){ 34 | //Build sql 35 | $client->queryBuilder()->get('user_list'); 36 | //Execute SQL 37 | var_dump($client->execBuilder()); 38 | }); 39 | ``` 40 | 41 | ::: danger 42 | Need to call execBuilder () to execute 43 | ::: 44 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/query.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # Query data 10 | 11 | ## Basic query 12 | 13 | Query a user data with id: 14 | 15 | ```php 16 | $client->queryBuilder()->where('id', 1)->getOne('user_list'); 17 | ``` 18 | 19 | Query multiple pieces of data: 20 | 21 | ```php 22 | $client->queryBuilder()->where('is_vip', 1)->get('user_list'); 23 | ``` 24 | 25 | ::: warning 26 | Get/getOne return value to view the detailed documentation in the chain operation 27 | ::: 28 | 29 | 30 | ::: tip Reminder 31 | You can use the chain operation method arbitrarily before using the operation methods such as `get` and `getOne` 32 | ::: 33 | -------------------------------------------------------------------------------- /docs/En/Components/Mysqli/update.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mysqli component 3 | meta: 4 | - name: description 5 | content: The Easyswoole Mysqli library is designed to make it easy for users to make a database call in an object-oriented form. And provide basic support for advanced usage such as Orm components. 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysqli|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # Update data 10 | 11 | ## WHERE UPDATE 12 | 13 | ```php 14 | $client->queryBuilder()->where('whereUpdate', 'whereValue')->update('updateTable', ['a' => 1]); 15 | ``` 16 | 17 | ## LIMIT UPDATE 18 | 19 | ```php 20 | $client->queryBuilder()->update('updateTable', ['a' => 1], 5); 21 | ``` 22 | 23 | ## Quick update 24 | 25 | ```php 26 | $client->queryBuilder() 27 | ->where('whereUpdate', 'whereValue') 28 | ->update('updateTable', [ 29 | 'age' => QueryBuilder::inc(1), 30 | 'number' => QueryBuilder::dec(3), 31 | ]); 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /docs/En/Components/Orm/Associat/preWithQuery.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ORM with Pre query 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM Component, 6 | - name: keywords 7 | content: swoole|swoole extand|swoole frame|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli Coroutine client|swoole ORM|ORM with pre query 8 | --- 9 | 10 | # Associated pre query 11 | 12 | In normal association, we can quickly associate query data after defining the relationship in the model class file. 13 | 14 | But at this time, we still need to get the association name manually to execute. 15 | 16 | Pre query provides a way to automatically query the usage of associated data as soon as the master data is queried. 17 | 18 | ORM version requires`>= 1.2.0` 19 | 20 | ## with method 21 | 22 | The with method passes in an array containing the association name already defined in the class file 23 | 24 | ```php 25 | $res = Model::create()->with(['user_list', 'user_store'])->get(1); 26 | 27 | var_dump($res); // At this time, there are already data of two associated fields, user list and user sotre. It is no longer necessary to call them manually first. 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/En/Components/Orm/DefineModel/specifyConnectionName.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Specify the connection name 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM component, 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM|Specify the connection name 8 | --- 9 | 10 | 11 | # Specify the connection name 12 | 13 | From the [Configuration Information Registration](/En/Components/Orm/configurationRegister) section, we already know that when registering configuration information, you can specify a `connection name' for this configuration. 14 | 15 | 16 | You can specify the connection configuration to be used by the model class custom property `connectionName`. The default is `default` 17 | 18 | 19 | Assume that a `read` connection name configuration has been registered through the configuration information registration section. 20 | 21 | Then we can define the ``` read ``` connection name in the Model. 22 | 23 | ```php 24 | Class AdminModel extends \EasySwoole\ORM\AbstractModel 25 | { 26 |      Protected $connectionName = 'read'; 27 | } 28 | ``` 29 | 30 | 31 | You can continue to see the [Reading and Writing Separation](/En/Components/Orm/readWriteSeparation) section for further details on how to use different database configurations. 32 | -------------------------------------------------------------------------------- /docs/En/Components/Orm/aggregation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: aggregation 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM component, 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM|aggregation 8 | --- 9 | 10 | 11 | # aggregation 12 | 13 | ORM also provides various aggregation methods such as count, max, min, avg, and sum. You can call any method after constructing the query: 14 | 15 | ## max 16 | 17 | ```php 18 | $max = TestUserListModel::create()->max('age'); 19 | ``` 20 | 21 | ## min 22 | 23 | ```php 24 | $min = TestUserListModel::create()->min('age'); 25 | ``` 26 | 27 | ## count 28 | 29 | ```php 30 | // count No need to pass field name 31 | $count = TestUserListModel::create()->count(); 32 | ``` 33 | 34 | ## avg 35 | 36 | ```php 37 | $avg = TestUserListModel::create()->avg('age'); 38 | ``` 39 | 40 | ## sum 41 | 42 | ```php 43 | $sum = TestUserListModel::create()->sum('age'); 44 | ``` 45 | 46 | -------------------------------------------------------------------------------- /docs/En/Components/Orm/defineModel.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Defining model 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM component, 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | 10 | # Defining model 11 | To define a model based model, just create a class and inherit `EasySwoole\ORM\AbstractModel` 12 | 13 | ```php 14 | 15 | = 4.4.8` 16 | - Easyswoole `>=3.3.2` 17 | - mysqli > `2.x` 18 | 19 | ```php 20 | composer require easyswoole/orm 21 | ``` 22 | 23 | ::: tip 24 | Orm的功能是依赖于mysqli 2.x组件的,update的$data参数将会传递给mysqli构造sql。 25 | 26 | 所以我们可以直接使用大部分mysqli的功能 27 | ::: 28 | -------------------------------------------------------------------------------- /docs/En/Components/Orm/invokeExecution.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Orm Invoke 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM component, 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | 10 | # orm invoke 11 | 12 | In the case of high concurrency, the shorter the waste time is, the better the service efficiency can be improved. 13 | 14 | By default, the ORM uses the defer method to obtain the connection resources in the pool, and returns them automatically when the collaboration exits. In this case, it will bring convenience and waste unnecessary resources. 15 | 16 | We can use the invoke method to return resources as soon as the ORM query is finished, which can improve the utilization of resources. 17 | ```php 18 | DbManager::getInstance()->invoke(function ($client){ 19 | 20 | $testUserModel = Model::invoke($client); 21 | $testUserModel->state = 1; 22 | $testUserModel->name = 'Siam'; 23 | $testUserModel->age = 18; 24 | $testUserModel->addTime = date('Y-m-d H:i:s'); 25 | 26 | $data = $testUserModel->save(); 27 | }); 28 | ``` 29 | 30 | 31 | ## Method support 32 | 33 | In this mode, there are two main methods to be explained. 34 | 35 | - Invoke method under DbManager (get a connection from the connection pool and return the connection when the closure is completed) 36 | - Invoke method of Model (inject client connection, no longer get from defer in connection pool) 37 | 38 | -------------------------------------------------------------------------------- /docs/En/Components/Orm/lastQuery.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ORM Last Execution Statement 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM component, 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # Last execution statement 10 | 11 | After a model executes a statement, it will save the executed statement to ` $model - > lastquery()`: 12 | 13 | ```php 14 | all()); 18 | //Print last executed`EasySwoole\Mysqli\QueryBuilder` object 19 | var_dump($model->lastQuery()); 20 | //Print the last executed SQL statement 21 | var_dump($model->lastQuery()->getLastQuery()); 22 | ``` 23 | 24 | ::: warning 25 | $model->lastQuery() Query object is returned, and specific documents can be viewed:[Query Builder](/EN/Mysqli/builder.md) 文档 26 | ::: 27 | -------------------------------------------------------------------------------- /docs/En/Components/Orm/popularScienceConcept.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Popular science concept 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM component, 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | # ORM Introduction 10 | 11 | Object Relational Mapping (ORM) is metadata that describes the mapping between code control and database. Objects in an object-oriented language program are automatically associated with the corresponding database. Essentially, the number of database communication operations is transformed into another form of object that is convenient for understanding and convenient operations. 12 | Each database table has a corresponding "model" that instantiates a new object with the model to interact with the table. You can query the data in the data table through the model and insert new records in the data table. 13 | -------------------------------------------------------------------------------- /docs/En/Components/Orm/specialQuery.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Special Query 3 | meta: 4 | - name: description 5 | content: Easyswoole ORM component, 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole mysql ORM|EasySwoole ORM|Swoole mysqli coroutine client|swoole ORM 8 | --- 9 | 10 | # Special Query 11 | 12 | ## find_in_set 13 | 14 | Generating conditions find_in_set(1, name) 15 | 16 | ? represents parameter binding. You can write the conditions directly. The second parameter is not passed, but you need to pay attention to prevent injection risk 17 | 18 | ```php 19 | $data = Model::create()->where("find_in_set(?, name)", [1])->get(); 20 | ``` 21 | 22 | ## complex where or 23 | 24 | ```php 25 | // Generate approximate statements:where status = 1 AND (id > 10 or id < 2) 26 | Model::create()->where('status', 1)->where(' (id > 10 or id <2) ')->get(); 27 | ``` 28 | -------------------------------------------------------------------------------- /docs/En/Components/Queue/install.md: -------------------------------------------------------------------------------- 1 | # Queue Introduction 2 | 3 | The Easyswoole package implements a lightweight queue, with Redis as the queue driver by default. 4 | 5 | You can implement a queue driver yourself to implement queue storage in kafka or boot mode. 6 | 7 | As you can see, Queue is not a separate component, it is more like a facade component that uniformly encapsulates different driver queues. 8 | 9 | # start installation 10 | 11 | ``` 12 | Composer require easyswoole/queue 13 | ``` 14 | 15 | # manual 16 | 17 | - Register queue driver 18 | - Set the consumption process 19 | - Producer delivery task 20 | 21 | ## Redis driver example 22 | 23 | ```php 24 | use EasySwoole\Redis\Config\RedisConfig; 25 | use EasySwoole\RedisPool\RedisPool; 26 | use EasySwoole\Queue\Driver\Redis; 27 | use EasySwoole\Queue\Queue; 28 | use EasySwoole\Queue\Job; 29 | 30 | $config = new RedisConfig([ 31 | 'host'=>'127.0.0.1' 32 | ]); 33 | $redis = new RedisPool($config); 34 | 35 | $driver = new Redis($redis); 36 | $queue = new Queue($driver); 37 | 38 | go(function ()use($queue){ 39 | while (1){ 40 | $job = new Job(); 41 | $job->setJobData(time()); 42 | $id = $queue->producer()->push($job); 43 | var_dump('job create for Id :'.$id); 44 | \co::sleep(3); 45 | } 46 | }); 47 | 48 | go(function ()use($queue){ 49 | $queue->consumer()->listen(function (Job $job){ 50 | var_dump($job->toArray()); 51 | }); 52 | }); 53 | ``` -------------------------------------------------------------------------------- /docs/En/Components/Redis/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Redis coroutine client 3 | meta: 4 | - name: description 5 | content: Redis coroutine client,Implemented by swoole coroutine client,Covers the method of redis 99% 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole redis| Swoole Redis coroutine client|swoole Redis|Redis coroutine 8 | --- 9 | ## Redis coroutine client 10 | Although swoole has its own coroutine client, we found some problems in the production environment: 11 | Swoole's redis client does not fully support Redis's full commands, such as geo search, and transactions, especially in cluster mode redis, which is not supported by the swoole client. To this end, we decided to implement a full version of the redis client using the swoole tcp client. 12 | 13 | 14 | ## Support method 15 | Currently, the redis client component already supports all methods except scripting (currently supports 178 methods): 16 | 17 | - connection 18 | - cluster 19 | - geohash 20 | - hash 21 | - keys 22 | - lists 23 | - pub/sub 24 | - server 25 | - string 26 | - sorted sets 27 | - sets 28 | - transaction 29 | - pipe 30 | 31 | > Due to more redis commands, 1 or 2 commands may be missed 32 | 33 | 34 | -------------------------------------------------------------------------------- /docs/En/Components/Redis/redis.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Redis coroutine client 3 | meta: 4 | - name: description 5 | content: Redis coroutine client,Implemented by swoole coroutine client,Covers the method of redis 99% 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole redis| Swoole Redis coroutine client|swoole Redis|Redis coroutine 8 | --- 9 | # Redis stand-alone client 10 | 11 | Example: 12 | ```php 13 | '127.0.0.1', 17 | 'port' => '6379', 18 | 'auth' => 'easyswoole', 19 | 'serialize' => \EasySwoole\Redis\Config\RedisConfig::SERIALIZE_NONE 20 | ])); 21 | var_dump($redis->set('a',1)); 22 | var_dump($redis->get('a')); 23 | }); 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/En/Components/apollo.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Apollo configuration center 3 | meta: 4 | - name: description 5 | content: EasySwoole Apollo configuration center 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|easyswoole|apollo 8 | --- 9 | # Apollo configuration center 10 | EasySwoole supports apollo data center. Synchronization can be configured according to this component. 11 | # apollo 12 | 13 | ## Installation 14 | 15 | ``` 16 | composer require easyswoole/apollo 17 | ``` 18 | 19 | ## Use 20 | 21 | ```php 22 | go(function (){ 23 | //Configure apollo server information 24 | $server = new \EasySwoole\Apollo\Server([ 25 | 'server'=>'http://106.12.25.204:8080', 26 | 'appId'=>'easyswoole' 27 | ]); 28 | //Create an apollo client 29 | $apollo = new \EasySwoole\Apollo\Apollo($server); 30 | //First sync 31 | var_dump( $apollo->sync('mysql')); 32 | //The second synchronization, if the server has not changed, then the result returned, isModify marked as fasle, with lastReleaseKey 33 | var_dump( $apollo->sync('mysql')); 34 | }); 35 | ``` 36 | 37 | 38 | ::: warning 39 | Can start a timer in the process to achieve automatic timing update 40 | ::: 41 | 42 | -------------------------------------------------------------------------------- /docs/En/Components/phpunit.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: EasySwoole利用phpunit进行单元测试 3 | meta: 4 | - name: description 5 | content: EasySwoole利用phpunit进行单元测试 swoole单元测试 协程环境单元测试 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole 单元测试|swoole 单元测试|swoole phpunit 8 | --- 9 | 10 | # Phpunit 11 | 12 | Easyswoole/Phpunit 是对 Phpunit 的协程定制化封装,主要为解决自动协程化入口的问题。并屏蔽了Swoole ExitException 13 | 14 | ## Installation 15 | ``` 16 | composer require easyswoole/phpunit 17 | ``` 18 | ## 使用 19 | 执行 20 | ``` 21 | ./vendor/bin/co-phpunit tests 22 | ``` 23 | 24 | 25 | ::: warning 26 | tests为你写的测试文件的目录,可以自定义 27 | ::: 28 | 29 | ## 预处理 30 | ```php 31 | /* 32 | * 允许自动的执行一些初始化操作,只初始化一次 33 | */ 34 | if(file_exists(getcwd().'/phpunit.php')){ 35 | require_once getcwd().'/phpunit.php'; 36 | } 37 | ``` 38 | 39 | easyswoole/phpunit 支持在项目目录下定义一个phpunit.php,用户可以在该文件下进行统一的测试前预处理 40 | 41 | 其他测试与phpunit一致 42 | 43 | ## EasySwoole中使用 44 | 自3.2.5版本的Easyswoole起,已经默认集成了 easyswoole/phpunit 组件。命令行下执行: 45 | ``` 46 | php easyswoole phpunit tests 47 | ``` 48 | 49 | 即可进行测试,若部分测试需要Http或者tcp等服务,可以先以启动easyswoole并进入守护模式,再进行测试 50 | 51 | 52 | 53 | ::: warning 54 | tests为你写的测试文件的目录,可以自定义 55 | ::: 56 | -------------------------------------------------------------------------------- /docs/En/Core/event.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 全局事件 3 | meta: 4 | - name: description 5 | content: 全局事件 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole|swoole|全局事件 8 | --- 9 | # Global vent 10 | 11 | Refer to different ways of writing Demo branches event: [The demo branch](https://github.com/easy-swoole/demo/branches) 12 | EasySwoole has five global events, all in easyswooleevent.php, which is generated after the framework is installed。 13 | 14 | - initialize [Framework initializes events] 15 | - mainServerCreate [The master service creates events] 16 | - onRequest Http [Request events] 17 | - afterRequest Http [After Request events] 18 | 19 | -------------------------------------------------------------------------------- /docs/En/Core/event/afterRequest.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: afterRequest 3 | meta: 4 | - name: description 5 | content: swoole事件,请求方法结束后执行 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole|swoole事件|afterRequest 8 | --- 9 | ## afterRequest 10 | 11 | ### The function prototype 12 | ```php 13 | public static function afterRequest(Request $request, Response $response): void 14 | { 15 | } 16 | ``` 17 | 18 | ## The sample 19 | You can trace the event to monitor the request and get the content of the response 20 | ```php 21 | public static function afterRequest(Request $request, Response $response): void 22 | { 23 | TrackerManager::getInstance()->getTracker()->endPoint('request'); 24 | 25 | $responseMsg = $response->getBody()->__toString(); 26 | Logger::getInstance()->console("Response content:".$responseMsg); 27 | // Response status code: 28 | // var_dump($response->getStatusCode()); 29 | 30 | 31 | // tracker end,After the end, you can see halfway set parameters, call stack running 32 | TrackerManager::getInstance()->closeTracker(); 33 | // TODO: Implement afterAction() method. 34 | } 35 | ``` 36 | 37 | -------------------------------------------------------------------------------- /docs/En/Core/event/initialize.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: initialize 3 | meta: 4 | - name: description 5 | content: 框架初始化事件 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole|swoole|initialize 8 | --- 9 | # Framework initializes Events 10 | 11 | ## The function prototype 12 | 13 | ```php 14 | public static function initialize(): void 15 | { 16 | } 17 | ``` 18 | 19 | ## Finished work 20 | 21 | EasySwoole has done the following when executing the framework initialization event: 22 | 23 | - The definition of the global constant EASYSWOOLE_ROOT 24 | - System default Log/Temp directory definition 25 | 26 | 27 | ## Processable content 28 | 29 | In this event, some system constant changes and global configuration can be made, for example: 30 | 31 | - Modify and create the system default Log/Temp directory。 32 | - Introduce user-defined configurations 33 | - Register database,redis connection pool 34 | - trace registration 35 | 36 | ## Call the coroutine API before starting 37 | ```php 38 | use Swoole\Coroutine\Scheduler; 39 | $scheduler = new Scheduler(); 40 | $scheduler->add(function() { 41 | /* Call the coroutine API */ 42 | }); 43 | $scheduler->start(); 44 | //Clear all timers 45 | \Swoole\Timer::clearAll(); 46 | ``` 47 | -------------------------------------------------------------------------------- /docs/En/Core/event/onReceive.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: onReceive 3 | meta: 4 | - name: description 5 | content: 当接收到客户端数据时,会触发此事件 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole|swoole|onReceive 8 | --- 9 | ## onReceive 10 | 11 | 主服务为SERVER时有效,当接收到客户端数据时,会触发此事件 12 | 13 | ###函数原型 14 | ```php 15 | public static function onReceive(\swoole_server $server, int $fd, int $reactor_id, string $data): void 16 | { 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/En/Core/lifecycle.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 框架生命周期 3 | meta: 4 | - name: description 5 | content: 框架生命周期 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole|swoole|框架生命周期 8 | --- 9 | ## 框架生命周期 10 | 11 | ![lifecycle](./lifecycle.png) 12 | -------------------------------------------------------------------------------- /docs/En/Core/lifecycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/En/Core/lifecycle.png -------------------------------------------------------------------------------- /docs/En/Core/other.md: -------------------------------------------------------------------------------- 1 | # Others to be added -------------------------------------------------------------------------------- /docs/En/HttpServer/problem.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Http service 3 | meta: 4 | - name: description 5 | content: Easyswoole, how to get the client IP 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|Easyswoole|Get client IP|cross domain processing 8 | --- 9 | 10 | 11 | # common problem 12 | ## How to get $HTTP_RAW_POST_DATA 13 | ```php 14 | $content = $this->request()->getBody()->__toString(); 15 | $raw_array = json_decode($content, true); 16 | ``` 17 | ## How to get the client IP 18 | For example, how to get the client IP in the controller 19 | ```php 20 | //Real address 21 | $ip = ServerManager::getInstance()->getSwooleServer()->connection_info($this->request()->getSwooleRequest()->fd); 22 | var_dump($ip); 23 | //Header address, for example after nginx proxy 24 | $ip2 = $this->request()->getHeaders(); 25 | var_dump($ip2); 26 | ``` 27 | 28 | ## HTTP status code is always 500 29 | Since the swoole **1.10.x** and **2.1.x** versions, in the http server callback, if response->end() is not executed, all 500 status codes are returned. 30 | 31 | ## How to setCookie 32 | Set the cookie by calling the setCookie method of the response object. 33 | ```php 34 | $this->response()->setCookie('name','value'); 35 | ``` 36 | More operations can be seen [Response object] (response.md) 37 | 38 | 39 | ## How to customize the App name 40 | Just modify the namespace registration of composer.json. 41 | ``` 42 | "autoload": { 43 | "psr-4": { 44 | "App\\": "Application/" 45 | } 46 | } 47 | ``` 48 | 49 | -------------------------------------------------------------------------------- /docs/En/Other/random.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Random generation problem 3 | meta: 4 | - name: description 5 | content: Easyswoole, randomly generated problem 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|Easyswoole|Random generation problem 8 | --- 9 | ## Random generation problem 10 | 11 | Due to the Swoole itself, when using random numbers, you need to pay extra attention. If `mt_rand` is called in the parent process, the result returned by calling `mt_rand` in different child processes will be the same. So you must call `mt_srand` to reseek in each child process. 12 | 13 | ::: warning 14 | `shuffle` and `array_rand` and other PHP functions that rely on random numbers will also be affected. 15 | ::: 16 | 17 | 18 | ## Scene example 19 | 20 | In asynchronous tasks, asynchronous processes, you need to pay attention to the problem of random number seeding, as in the following example. 21 | 22 | ```php 23 | mt_rand(0, 1); // Mt_rand has been called here and has been automatically seeded within the parent process 24 | $worker_num = 16; 25 | 26 | // Fork process 27 | for ($i = 0; $i < $worker_num; $i++) { 28 | $process = new swoole_process('child_async', false, 2); 29 | $pid = $process->start(); 30 | } 31 | 32 | function child_async(swoole_process $worker) 33 | { 34 | mt_srand(); // Must be replanted here, otherwise the same result will be obtained 35 | echo mt_rand(0, 100) . PHP_EOL; 36 | $worker->exit(); 37 | } 38 | ``` 39 | 40 | -------------------------------------------------------------------------------- /docs/En/Other/traitSingleTon.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Trait and singleton 3 | meta: 4 | - name: description 5 | content: Easyswoole, Trait and singleton 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|Easyswoole|Trait and singleton 8 | --- 9 | 10 | ## Trait and singleton 11 | 12 | ```php 13 | 14 | trait A{ 15 | private static $instance; 16 | static function getInstance() 17 | { 18 | if(!isset(self::$instance)){ 19 | self::$instance = new static(); 20 | } 21 | return self::$instance; 22 | } 23 | } 24 | 25 | class B{ 26 | use A; 27 | function a() 28 | { 29 | var_dump('call at B'); 30 | } 31 | } 32 | 33 | class C extends B{ 34 | function a() 35 | { 36 | var_dump('call at c'); 37 | parent::a(); // TODO: Change the autogenerated stub 38 | } 39 | } 40 | 41 | class D extends B{ 42 | use A; 43 | function a() 44 | { 45 | var_dump('call at D'); 46 | parent::a(); // TODO: Change the autogenerated stub 47 | } 48 | } 49 | $b = B::getInstance(); 50 | $c = C::getInstance(); 51 | $d = D::getInstance(); 52 | 53 | $c->a(); 54 | $d->a(); 55 | 56 | ``` 57 | 58 | Above output: 59 | ```php 60 | string(9) "call at B" 61 | string(9) "call at D" 62 | string(9) "call at B" 63 | 64 | ``` 65 | -------------------------------------------------------------------------------- /docs/En/Preface/componentUpdateLog.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Component update record 3 | meta: 4 | - name: description 5 | content: easyswooleComponent update record 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|easyswoole|Component update record|Framework update 8 | --- 9 | 10 | 11 | # 2019-10 12 | 13 | ## New addition 14 | - [#14](https://github.com/easy-swoole/orm/pull/14) `ORM` increase `coherent operation`, `aggregate query` 15 | - [#19](https://github.com/easy-swoole/orm/pull/19) `ORM` adds `alias coherent operation support`, `support` to directly get join and other data not defined in the table structure, `get method adds second parameter returnAsArray` 16 | -------------------------------------------------------------------------------- /docs/En/Preface/contactAuthor.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Contact author 3 | meta: 4 | - name: description 5 | content: Contact easyswoole author 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|easyswoole | easyswoole contact us | easyswoole author 8 | --- 9 | # Contact author 10 | 11 | - Author WeChat 12 | 13 | ![](/resources/authWx.png) 14 | 15 | - Commercial support: 16 | - QQ 291323003 17 | - EMAIL admin@fosuss.com 18 | 19 | - QQ exchange group 20 | - VIP group 579434607 (this group needs to pay 599 RMP) 21 | - EasySwoole official group 633921431 (full) 22 | - EasySwoole official two groups 709134628 (full) 23 | - EasySwoole official three groups 932625047 24 | -------------------------------------------------------------------------------- /docs/En/Preface/team.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Document maintenance team 3 | meta: 4 | - name: description 5 | content: EasySwoole Open source team, Document Maintenance Team Introduction, EasySwoole Community 6 | - name: keywords 7 | content: swoole|swoole extension|swoole framework|EasySwoole | EasySwoole open source team | EasySwoole Community | Document maintenance team 8 | --- 9 | 10 | 11 | # Building the EasySwoole Community Program 12 | 13 | Invite you to join the EasySwoole Community Maintenance Team 14 | 15 | You can get 16 | 17 | - Guidance on EasySwoole related issues 18 | - EasySwoole Contributor Logo 19 | - Basic knowledge related to Swoole 20 | 21 | We hope that you can 22 | 23 | - Find issues in the EasySwoole documentation 24 | - Feedback on issues in the EasySwoole documentation 25 | - Write and modify EasySwoole documentation 26 | - Maintain community system content 27 | 28 | # Join us 29 | 30 | Contact 31 | 32 | - QQ: 59419979 33 | - Email: 59419979@qq.com 34 | 35 | 36 | # Document maintenance team 37 | 38 | To be added 39 | 40 | -------------------------------------------------------------------------------- /docs/HttpServer/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Easyswoole http服务 3 | meta: 4 | - name: description 5 | content: easyswoolehttp服务 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|http服务|swoole http 8 | --- 9 | 10 | # http服务 11 | 12 | http组件是当`SERVER_TYPE`为`EASYSWOOLE_WEB_SERVER`自动启用的组件,它实现了控制器连接池,url解析以及url路由规则. 13 | [http组件demo](https://github.com/easy-swoole/demo/tree/3.x-http) 14 | 15 | ## 命名空间 16 | 我们首先需要在`composer.json`中注册应用目录的命名空间(控制器命名空间默认为`App\HttpController`) 17 | ```json 18 | { 19 | "require": { 20 | "easyswoole/easyswoole": "^3.1" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "App\\": "App/" 25 | } 26 | } 27 | } 28 | ``` 29 | 然后更新一下composer 30 | ```` 31 | composer update 32 | ```` 33 | 34 | ## 约定规范 35 | 36 | - 项目中类名称与类文件(文件夹)命名,均为大驼峰,变量与类方法为小驼峰。 37 | - 在HTTP响应中,于业务逻辑代码中echo $var 并不会将$var内容输出至相应内容中,请调用Response实例中的wirte()方法实现。 38 | 39 | ## 默认控制器 40 | 创建`App/HttpController/Index.php`文件: 41 | ````php 42 | response()->write('hello world'); 57 | // TODO: Implement index() method. 58 | } 59 | } 60 | ```` 61 | 62 | 启动easyswoole: 63 | ```` 64 | php easyswoole start 65 | ```` 66 | 访问ip:9501,即可看到输出"hello world"; 67 | 68 | 69 | -------------------------------------------------------------------------------- /docs/HttpServer/psr7.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: PSR-7 3 | meta: 4 | - name: description 5 | content: easyswoole,easyswoole完全兼容PSR7 Http Message接口规范 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|PSR7 8 | --- 9 | 10 | #PSR-7 Http Message 11 | easyswoole完全兼容PSR7 Http Message接口规范。 12 | ## 接口规范示例 13 | [http://www.php-fig.org/psr/psr-7/](http://www.php-fig.org/psr/psr-7/) 14 | 15 | ## 部分对象详解 16 | ### Stream 对象 17 | easySwoole中利用php://memory实现Stream对象,(新手可以把Stream理解为一个字符串对象),所有的操作均为二进制安全,且完全是内存IO,因此效率极高,不会由于磁盘IO问题影响执行速度。 18 | - __toString 19 | 返回Stream对象中完整的流数据。 20 | - close 21 | 关闭当前流对象,流对象中的数据也随之清空。 22 | - detach 23 | 将流对象里面的资源(文件流句柄)从Stream对象中抽离。 24 | > 注意:抽离后,该Stream对象将不再不可用。 25 | - getSize 26 | 获取当前Stream对象中数据的大小(长度)。 27 | - tell 28 | 获取当前数据流指针所处位置。 29 | - eof 30 | 判断当数据流指针是否处于资源结束位置。 31 | - isSeekable 32 | - seek 33 | 移动数据流指针到指定位置。 34 | - rewind 35 | 将数据流指针移动至开始位置。 36 | - isWritable 37 | - write 38 | 向当前数据流写入数据。 39 | > 注意:写入时应该注意数据流指针所处位置。 40 | - isReadable 41 | - read 42 | - getContents 43 | - getMetadata 44 | 45 | ### UploadFile 对象 46 | easySwoole中,所有的文件均自动转化为UploadFile对象。 47 | - getStream 48 | 返回上传文件的数据流。 49 | - moveTo 50 | 将上传文件存为实体文件。 51 | >注意:moveTo以file_put_contents实现,因此请确保保存文件时,文件存储路劲已经存在且有写入权限。 52 | - getSize 53 | 获取文件大小。 54 | - getError 55 | 获取文件上传时的错误信息。 56 | - getClientFilename 57 | 获取文件的客户端文件名。 58 | - getClientMediaType 59 | 60 | -------------------------------------------------------------------------------- /docs/HttpServer/response.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Response对象 3 | meta: 4 | - name: keywords 5 | content: swoole|swoole 拓展|swoole 框架|easyswoole Response对象|swoole response 对象|swoole http|swoole 6 | --- 7 | # Response对象 8 | ## 生命周期 9 | Response对象在系统中以单例模式存在,自收到客户端HTTP请求时自动创建,直至请求结束自动销毁。Response对象完全符合[PSR7](psr-7.md)中的所有规范。 10 | 其他细节方法,有兴趣的同学可以在IDE中查看对应的代码。 11 | 12 | ## 方法列表 13 | ### write 14 | 该方法用于向客户响应数据。 15 | ``` 16 | $this->response()->write('hello world'); 17 | ``` 18 | 19 | ### redirect 20 | 该方法用于将请求重定向至指定的URL 21 | ``` 22 | $this->response()->redirect("/newURL/index.html"); 23 | ``` 24 | ### setCookie 25 | 向客户端设置一个Cookie,用法与原生的setCookie一致。 26 | ### getSwooleResponse 27 | 用于获取原始的swoole_http_response实例。 28 | ### end 29 | 结束对该次HTTP请求响应,结束之后,无法再次向客户端响应数据. 30 | ### isEndResponse 31 | 判断该次HTTP请求是否结束响应,当你不知道是否已经结束响应时,可通过该方法判断是否能再次向客户端响应数据: 32 | ```php 33 | if(!$this->response()->isEndResponse()){ 34 | $this->response()->write('继续发送数据'); 35 | } 36 | ``` 37 | ## PSR-7规范Response对象中常用方法 38 | 39 | ### withStatus 40 | 41 | 向客户端发送HTTP状态码。 42 | 43 | ```php 44 | $this->response()->withStatus($statusCode); 45 | ``` 46 | 47 | ::: warning 48 | 注意:$statusCode必须为标准的HTTP允许状态码,具体请见Http Message中的Status对象。 49 | ::: 50 | 51 | ### withHeader 52 | 用于向HTTP客户端发送一个header。 53 | ```php 54 | $this->response()->withHeader('Content-type','application/json;charset=utf-8'); 55 | ``` 56 | -------------------------------------------------------------------------------- /docs/Introduction/coroutineCreate.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Easyswoole协程环境 3 | meta: 4 | - name: description 5 | content: swoole,easyswoole协程介绍 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole 协程|php 协程|swoole 8 | --- 9 | 10 | # 协程 11 | 12 | ::: tip 13 | 从4.0版本开始`Swoole`提供了完整的协程(Coroutine)+ 通道(Channel)特性,带来全新的CSP编程模型。应用层可使用完全同步的编程方式,底层自动实现异步IO。 14 | ::: 15 | 16 | 协程可以理解为纯用户态的线程,其通过协作而不是抢占来进行切换。相对于进程或者线程,协程所有的操作都可以在用户态完成,创建和切换的消耗更低。Swoole可以为每一个请求创建对应的协程,根据IO的状态来合理的调度协程,这会带来了以下优势: 17 | 18 | 开发者可以无感知的用同步的代码编写方式达到异步IO的效果和性能,避免了传统异步回调所带来的离散的代码逻辑和陷入多层回调中导致代码无法维护 19 | 同时由于底层封装了协程,所以对比传统的PHP层协程框架,开发者不需要使用yield关键词来标识一个协程IO操作,所以不再需要对yield的语义进行深入理解以及对每一级的调用都修改为yield,这极大的提高了开发效率 20 | 可以满足大部分开发者的需求。对于私有协议,开发者可以使用协程的TCP或者UDP接口去方便的封装。 21 | 22 | 23 | # 注意事项 24 | 25 | - 全局变量:协程使得原有的异步逻辑同步化,但是在协程的切换是隐式发生的,所以在协程切换的前后不能保证全局变量以及static变量的一致性。 26 | - 与xdebug、xhprof、blackfire等zend扩展不兼容,例如不能使用xhprof对协程server进行性能分析采样。 27 | 28 | 29 | # 创建协程 30 | 31 | ```php 32 | go(function () { 33 | co::sleep(0.5); 34 | echo "hello"; 35 | }); 36 | go("test"); 37 | go([$object, "method"]); 38 | ``` 39 | -------------------------------------------------------------------------------- /docs/Introduction/demo.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Deomo 3 | meta: 4 | - name: description 5 | content: EasySwoole强大的生态贡献了许多的Demo 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|demo|admin 8 | --- 9 | 10 | # Demo 11 | 12 | ### EasySwoole-Chat 13 | 14 | 基于EasySwoole V3 实现的聊天室 15 | 16 | [聊天室Demo地址](https://github.com/easy-swoole/demo/tree/3.x-chat) 17 | 18 | ### EasySwoole-Admin 19 | 20 | 基于EasySwoole框架的后台,内使用Policy组件、FastCache组件、mysqli连接池组件等。用于:api开发过程学习、组件使用学习、项目后台。 21 | 22 | [admin后台模板地址](https://github.com/xuanyanwow/easyswoole_admin) 23 | 24 | ### EasySwoole-Http-Monitor 25 | 26 | 开发工具,可以记录最近的http请求,并且分析参数、复发请求,如微信异步回调调试,支付一单,可以反复模拟推送回调,直到程序走通。 27 | 28 | [http监控工具地址](https://github.com/xuanyanwow/easyswooleHttpMonitor) 29 | 30 | ### curdAutomaticGeneration 31 | 32 | 快速根据数据库生成CURD代码,包括全套bean,model,controller。代码分层,快速开发增删改查功能模块。 33 | 34 | [自动写代码工具地址](https://github.com/tioncico/curdAutomaticGeneration) 35 | 36 | ### jin-Chat 37 | 38 | 是基于EasySwoole V3 并整合ES文档中的mysq/redisl协程连接池、Task异步任务、ceche缓存、chat聊天等功能的完整IM应用(demo) 39 | 40 | [im Demo地址](https://github.com/Double-Jin/jin-chat) 41 | 42 | ### socialite (第三方登录集成组件) 43 | 44 | 基于 overtrue/socialite改造的,适用于easyswoole的第三方登录组件,现已支持wechat,qq,weibo,github,facebook 45 | 46 | [第三方登录集成组件地址](https://github.com/xbing2002/socialite) 47 | -------------------------------------------------------------------------------- /docs/Introduction/environment.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Easyswoole环境要求 3 | meta: 4 | - name: description 5 | content: EasySwoole的基础环境要求与swoole的安装 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|swoole 扩展|swoole框架|swoole 8 | --- 9 | 10 | # 环境要求 11 | 12 | 满足基本的环境要求才能运行框架,easySwoole 框架对环境的要求十分简单,只需要满足运行 Swoole 拓展的条件,并且 PHP 版本在 7.1 以上即可 13 | 14 | - [GitHub](https://github.com/easy-swoole/easyswoole) 喜欢记得点个 ***star*** 15 | - [GitHub for Doc](https://github.com/easy-swoole/doc) 16 | 17 | ## 基础运行环境 18 | 19 | - 保证 **PHP** 版本大于等于 **7.1** 20 | 21 | 22 | - 保证 **Swoole** 拓展版本大于等于 **4.4.12** 23 | - 需要 **pcntl** 拓展的任意版本 24 | - 使用 **Linux** / **FreeBSD** / **MacOS** 这三类操作系统 25 | - 使用 **Composer** 作为依赖管理工具 26 | 27 | 28 | ::: warning 29 | 参考下面的建议,它们都不是必须的,但是有助于更高效的使用框架和进行开发 30 | ::: 31 | 32 | - 使用 **Ubuntu14** / **CentOS 7.0** 或更高版本操作系统 33 | 34 | ## 其他 35 | 36 | - QQ交流群 37 | - VIP群 579434607 (本群需要付费599元) 38 | - EasySwoole官方一群 633921431(已满) 39 | - EasySwoole官方二群 709134628(已满) 40 | - EasySwoole官方三群 932625047 41 | 42 | - 商业支持: 43 | - QQ 291323003 44 | - EMAIL admin@fosuss.com 45 | 46 | - 作者微信 47 | 48 | ![](/resources/authWx.png) 49 | 50 | - [捐赠](../Preface/donation.md) 51 | 您的捐赠是对EasySwoole项目开发组最大的鼓励和支持。我们会坚持开发维护下去。 您的捐赠将被用于: 52 | 53 | - 持续和深入地开发 54 | - 文档和社区的建设和维护 55 | 56 | - **easySwoole** 的文档采用 **GitBook** 作为文档撰写工具,若您在使用过程中,发现文档有需要纠正 / 补充的地方,请 **fork** 项目的文档仓库,进行修改补充,提交 **Pull Request** 并联系我们 57 | -------------------------------------------------------------------------------- /docs/NoobCourse/Async.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/NoobCourse/Async.png -------------------------------------------------------------------------------- /docs/NoobCourse/Composer.md: -------------------------------------------------------------------------------- 1 | ## Composer 2 | Composer 是 PHP5.3以上 的一个依赖管理工具。它允许你声明项目所依赖的代码库,它会在你的项目中为你安装他们。Composer 不是一个包管理器。是的,它涉及 "packages" 和 "libraries",但它在每个项目的基础上进行管理,在你项目的某个目录中(例如 vendor)进行安装。默认情况下它不会在全局安装任何东西。因此,这仅仅是一个依赖管理。 3 | 4 | >可以这么理解,composer是一个实现了自动加载的框架,它可以通过配置的声明,下载相应的依赖,代码库,并通过配置,使其能psr-4规范被正确的自动引入 5 | >详细文档可查看composer文档:https://github.com/5-say/composer-doc-cn 6 | 7 | ### composer使用步骤 8 | * 安装composer 9 | * 创建composer项目,自动生成composer.json 10 | * 通过composer.json配置需要加载的代码库 11 | * 通过composer install下载代码库,依赖 12 | * 框架引入composer的autoload.php 13 | * 即可实现自动加载代码 14 | 15 | 16 | ### 常用命令 17 | ``` 18 | composer install; #安装包,根据composer.json 19 | composer update; #更新包,升级composer.json的所有代码库(如果能升级的话) 20 | composer search 关键字; #搜索包,搜索composer可用的包 21 | composer require 包名称; #引入包,会在composer.json新增一条包配置,并下载该代码包 22 | composer remove 包名称; #删除包 23 | composer dump-autoload;#生成当前命名空间与类库文件路径的一个映射,运行时加载会直接读取这个映射,加快文件的加载速度。 24 | ``` 25 | 26 | 27 | -------------------------------------------------------------------------------- /docs/NoobCourse/Conversation/Introduction.md: -------------------------------------------------------------------------------- 1 | ## 会话管理 2 | 在[http协议](../NetworkrPotocol/tcp/http.md)中,我们了解到了,http每次请求都是握手/挥手,第二次和第一次请求时没有任何关联的,属于无状态协议,那么问题来了,既然http是无状态协议,那服务器是怎么区分不同的用户的呢?,这就是会话了 3 | 4 | ### 基础讲解 5 | 服务器能区分用户的原理主要就是在于会话,每次发起http请求时,都附加上一条身份识别数据,例如下面这个http请求头: 6 | 7 | ``` 8 | GET / HTTP/1.1 9 | Host: www.easyswoole.com 10 | Connection: keep-alive 11 | Pragma: no-cache 12 | Cache-Control: no-cache 13 | Upgrade-Insecure-Requests: 1 14 | User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4094.1 Safari/537.36 15 | Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 16 | Accept-Encoding: gzip, deflate, br 17 | Accept-Language: zh-CN,zh;q=0.8 18 | Cookie: Hm_lvt_4c8d895ff3b25bddb6fa4185c8651cc3=1541986142,1542074627,1542158990,1542252497; Hm_lpvt_4c8d895ff3b25bddb6fa4185c8651cc3=1542252498 19 | ``` 20 | 抛开http本身需要的数据,我们讲解下: 21 | ``` 22 | User-Agent: 用户端信息,浏览器的各种信息 23 | Cookie: cookie会话 24 | ``` 25 | 服务端可以通过User-Agent获得用户的浏览器信息,可以通过cookie获取自定义的信息 26 | 所以我们可以: 27 | * 用户A第一次进入,没有附带cookie 28 | * 服务端记录这个用户,响应头增加一个set_cookie:id=1的cookie 29 | * 浏览器获得响应头,解析到set_cookie动作,把id=1存进cookie 30 | * 第二次请求服务端,带上id=1的cookie,服务端就可以知道:这次请求时用户A请求的 31 | * 同理,用户B第一次进入,服务端响应set_cookie:id=2 32 | * ... 33 | 34 | 可以看出,只要用户端每次请求,跟服务端约定好一个参数作为用户标识,服务端就可以通过这个标识区分不同的用户了 -------------------------------------------------------------------------------- /docs/NoobCourse/Conversation/Session.md: -------------------------------------------------------------------------------- 1 | ## Session 2 | 在计算机中,尤其是在网络应用中,称为“会话控制”。Session 对象存储特定用户会话所需的属性及配置信息。这样,当用户在应用程序的 Web 页之间跳转时,存储在 Session 对象中的变量将不会丢失,而是在整个用户会话中一直存在下去。 3 | 4 | 当用户请求来自应用程序的 Web 页时,如果该用户还没有会话,则 Web 服务器将自动创建一个 Session 对象。当会话过期或被放弃后,服务器将终止该会话。 5 | 6 | 注意 会话状态仅在支持 cookie 的浏览器中保留。 7 | 8 | ### 会话实现原理 9 | session会话的实现原理大概如下所示: 10 | * 用户A第一次进入,没有附带任何标识信息(通常是cookie) 11 | * 服务端接收请求,给与用户A一个会话标识(通常是set_cookie,cookie值将加密) 12 | * 服务端根据会话标识,在服务器本地存储用户信息 13 | * 用户A端获取到会话标识,存储到用户端本地 14 | * 用户A第二次请求,附带会话标识(通常是cookie) 15 | * 服务端通过会话标识,找到服务端相应的用户信息 16 | 17 | 18 | ### php中的session 19 | php已经内置封装好了一个功能完整的会话管理,基础用法为: 20 | ```php 21 | 为了安全,服务端可设定token有效时间,以及加密token,每隔一段时间变动一次token等. -------------------------------------------------------------------------------- /docs/NoobCourse/Coroutine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/NoobCourse/Coroutine.png -------------------------------------------------------------------------------- /docs/NoobCourse/EasySwoole/Demo.md: -------------------------------------------------------------------------------- 1 | ## Demo 2 | 目前EasySwoole文档相当完善,并且每个功能点都有代码示例,可通过下载demo,与文档对比学习EasySwoole框架: 3 | https://github.com/easy-swoole/demo 4 | 5 | -------------------------------------------------------------------------------- /docs/NoobCourse/EasySwoole/DesignIdea.md: -------------------------------------------------------------------------------- 1 | ## 设计理念 2 | 以下是作者原话: 3 | ``` 4 | 最早接触Swoole,是2015年年初,为实现一个可以实时控制的多进程爬虫而接触的Swoole,进而为Swoole的各种便捷、高效所着迷。 5 | 为此,做了综合技术评审之后,公司决定开始全线推展Swoole,并利用Swoole实现承载每天对外过亿的任务爬取与投递服务。2017年年初,在[Rango](http://rango.swoole.com/)的鼓励下,我决定将框架进行开源,并在Rango的建议下,命名为EasySwoole。 6 | ``` 7 | 8 | 目前为止,EasySwoole框架文档越来越完善,秉承着`Easy`学swoole,编写了这次的新手入门教程,让更多的phper能够更好,更快,更加容易的入门swoole,拥抱swoole的怀抱 9 | -------------------------------------------------------------------------------- /docs/NoobCourse/EasySwoole/Introduction.md: -------------------------------------------------------------------------------- 1 | ## EasySwoole 2 | EasySwoole 是一款基于Swoole Server 开发的常驻内存型的分布式PHP框架,专为API而生,摆脱传统PHP运行模式在进程唤起和文件加载上带来的性能损失。EasySwoole 高度封装了 Swoole Server 而依旧维持 Swoole Server 原有特性,支持同时混合监听HTTP、自定义TCP、UDP协议,让开发者以最低的学习成本和精力编写出多进程,可异步,高可用的应用服务。 3 | 4 | -------------------------------------------------------------------------------- /docs/NoobCourse/EasySwoole/RunSteps.md: -------------------------------------------------------------------------------- 1 | ## EasySwoole运行步骤 2 | EasySwoole的框架运行步骤大概为以下几步: 3 | 4 | * 从php easyswoole start开始,首先进行了目录常量定义,临时目录,日志目录定义, 5 | * 触发`initialize`,这个事件你可以进行一些服务注册,修改临时目录,日志目录等 6 | * 获取框架配置,监听ip,端口,worker进程数,子服务配置,回调等,准备开启swoole服务 7 | * 触发`mainServerCreate`,这个事件你可以自行重新配置监听ip,端口,回调事件,框架异常,等等 8 | * 框架根据配置,启动swoole服务,附带子服务(如果有配置的话) 9 | 10 | 到这个时候,框架已经是启动成功了,由于swoole_server的特性,开启之后会常驻内存(进程会一直运行,可以理解成一直在while(1){}),等待请求进入然后回调. 11 | 用户请求步骤: 12 | * 用户请求 13 | * swoole_server触发回调事件,经过框架解析 14 | * 触发 `onRequest`(http服务时),`onReceive`(tcp服务时) 15 | * 经过http组件的调度,调用控制器方法完毕 16 | * 触发 `afterRequest` 事件,表明这次请求已经要结束 17 | * es将响应数据交回给swoole_server,给客户端响应数据 18 | 19 | -------------------------------------------------------------------------------- /docs/NoobCourse/EasySwoole/Section.md: -------------------------------------------------------------------------------- 1 | ## 组件设计 2 | EasySwoole3.x版本采用组件分离设计,可自行选择需要的组件进行添加使用,框架本身只实现了基础的封装,框架变的更加简洁,轻便 3 | 4 | ### 组件列表 5 | 目前EasySwoole3.x开源组件如下: 6 | * validate 验证组件 7 | * http http组件,实现了对http控制器的调度封装等 8 | * mysqli 协程版mysqli组件 9 | * rpc rpc组件,可实现rpc分布式 10 | * socket socket组件,实现了对tcp/udp的控制器调度 11 | * trace trace组件,代码追踪 12 | * component 基础组件库 13 | * utility 工具类库 14 | * verifyCode 验证码生成组件 15 | * spl spl组件 16 | * curl curl组件 17 | 18 | 19 | -------------------------------------------------------------------------------- /docs/NoobCourse/Introduction.md: -------------------------------------------------------------------------------- 1 | ## 新手入门 2 | 本文适用于那些对Swoole/EasySwoole毫无了解,只用过传统fpm框架的开发者,看完这个教程,你将可以入门Swoole/EasySwoole 3 | 4 | ### 学习要求 5 | 在观看本教程时,请先确认你的技术基础是否满足: 6 | 7 | * php语法基础(菜鸟教程/慕课网可学) 8 | * php面对对象基础(菜鸟教程/慕课网可学) 9 | * php设计模式(http://www.imooc.com/learn/236) 10 | * php异常,错误处理(http://www.imooc.com/learn/380) 11 | * 使用过fpm框架开发或对mvc框架有了解 12 | * 能安装linux系统,以及基础使用 13 | * 开发经验半年以上 14 | * 有着 百度/谷歌 搜索答案的经历 15 | 16 | ### 注意事项 17 | 为了您能学会该教程,请注意一下事项: 18 | * 教程每个章节都有看完 19 | * 不懂的技术语句有去搜索了解 20 | * 请不要跳章节学习,每个章节都有存在的必要 -------------------------------------------------------------------------------- /docs/NoobCourse/Linux.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/NoobCourse/Linux.md -------------------------------------------------------------------------------- /docs/NoobCourse/Linux/Command.md: -------------------------------------------------------------------------------- 1 | ## 命令基础 2 | 3 | linux命令存储以下位置: 4 | * /bin(指向/usr/bin)目录,包含基本的用户命令,默认全体用户都可使用,例如`curl`,`ls`命令 5 | * /sbin(指向/usr/sbin),/usr/local/sbin,存放需要root权限的命令以及工具,默认root用户使用,例如`ip`,`halt`命令 6 | * /usr/local/bin 给用户放置自己的可执行程序的地方,不会被系统升级覆盖 7 | * /usr/local/sbin 给管理员放置自己的可执行程序的地方,不会被系统升级覆盖 8 | 9 | 如果在每个命令目录都存在某个命令时,通过系统的`$PATH`变量决定优先级 10 | ``` 11 | echo $PATH 12 | # 每台电脑输出不同,/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/protobuf/bin/:/root/bin 13 | ``` 14 | 所以,当你输入 `ls` 命令,点击回车时,系统会以此从各个目录找到这个命令文件,然后执行该文件. 15 | 16 | ##### 执行当前目录文件 17 | 如果你的程序命令没有放在以上文件夹,我们也可通过相对路径以及绝对路径启动该命令: 18 | ``` 19 | ./php -m #当你在php命令文件目录中时, 20 | /www/server/php/72/bin/php -m,宝塔php命令目录 21 | ``` 22 | 根据这个原理,我们可以安装多个php版本,并启动 23 | ``` 24 | /www/server/php/72/bin/php -m 25 | /www/server/php/56/bin/php -m 26 | ``` 27 | -------------------------------------------------------------------------------- /docs/NoobCourse/Linux/Extention.md: -------------------------------------------------------------------------------- 1 | ## php扩展安装 2 | 在windows中,只需要将dll文件移动到扩展目录,并在php.ini中引入即可 3 | linux中类似,我们需要安装扩展的软件(例如mysql扩展,我们需要先安装mysql),再安装mysql操作扩展(mysqli,pdo)生成.so文件,在php.ini中引入.so文件即可 4 | 5 | ### 编译安装 6 | swoole扩展,先下载swoole官方源码:https://github.com/swoole/swoole-src 7 | 解压,进入目录 8 | ``` 9 | phpize #当不存在./configure时 10 | ./configure --with-php-config=/usr/local/php/bin/php-config 11 | make 12 | make install 13 | ``` 14 | 这时候.so文件会自动生成到php扩展目录(有些扩展需要自己移动进去), 15 | 在php.ini最后面加上 16 | ``` 17 | extension = swoole.so 18 | ``` 19 | 然后`php -m`查看扩展,就能看到swoole扩展安装好了 -------------------------------------------------------------------------------- /docs/NoobCourse/Linux/Firewall.md: -------------------------------------------------------------------------------- 1 | ## 防火墙 2 | 当你开启一个tcp服务,却发现访问不了,那么你得考虑下是否是防火墙拦截了, 3 | 目前,最常见的拦截有以下几种情况: 4 | * 服务器本机防火墙拦截 5 | * 服务器供应商拦截(阿里云,腾讯云安全组) 6 | 7 | 服务器本机拦截,可通过防火墙管理软件,开端口,或者直接关闭防火墙进行解决(不建议): 8 | 例如centos 7下,防火墙管理软件为firewalld. 9 | 基础命令为: 10 | ``` 11 | systemctl start firewalld;#启动 12 | systemctl stop firewalld;#停止 13 | systemctl status firewalld;#查看状态 14 | systemctl disable firewalld;#开机禁用 15 | systemctl enable firewalld;#开启启动 16 | firewall-cmd --zone=public --add-port=80/tcp --permanent #开放80/tcp端口 (--permanent永久生效,没有此参数重启后失效); 17 | firewall-cmd --reload;# 18 | firewall-cmd --zone= public --query-port=80/tcp;#查看80/tcp端口 19 | firewall-cmd --zone= public --remove-port=80/tcp --permanent;#删除该端口开放 20 | ``` 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /docs/NoobCourse/Linux/Introduction.md: -------------------------------------------------------------------------------- 1 | ## Linux 2 | Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户、多任务、支持多线程和多CPU的操作系统。它能运行主要的UNIX工具软件、应用程序和网络协议。它支持32位和64位硬件。Linux继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统。 3 | 4 | ### Linux的发行版 5 | Linux的发行版说简单点就是将Linux内核与应用软件做一个打包。 6 | 目前市面上较知名的发行版有:Ubuntu、RedHat、CentOS、Debian、Fedora、SuSE、OpenSUSE、Arch Linux、SolusOS 等。 7 | 8 | >可自行搜索安装方法,推荐使用虚拟机安装,或docker镜像等 9 | 10 | 11 | ### 一切皆文件 12 | linux `一切皆文件`,在linux系统中,所有东西都是用文件来表示的,例如磁盘,内存,鼠标,显示器,socket,都是以文件来标识的,任何设备都是通过操作文件(写入,读取)的方式来操作 13 | ### windows连接linux 14 | 连接linux终端需要使用ssh协议工具进行连接,linux必须开启ssh连接(默认开启) 15 | windows ssh工具推荐: 16 | * phpstorm自带ssh,以及sftp 17 | * Secure CRT 18 | * putty 19 | 20 | 可自行搜索下载 21 | 22 | ### 详细教程可自行搜索了解,建议菜鸟教程 -------------------------------------------------------------------------------- /docs/NoobCourse/Linux/Lnmp.md: -------------------------------------------------------------------------------- 1 | ## LNMP 2 | LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。 3 | 4 | Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。 5 | 6 | Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。 7 | 8 | Mysql是一个小型关系型数据库管理系统。 9 | 10 | PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。 11 | 12 | 这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。 13 | 14 | 15 | ## 安装 16 | lnmp环境安装有以下几种方法: 17 | * yum,apt-get 软件包安装 18 | * 编译安装 19 | * 集成一键安装 20 | 21 | 由于软件包安装步骤较多,可自行搜索了解详细 22 | 23 | ### 编译安装 24 | 编译安装主要步骤为(需要有编译器): 25 | * 下载软件源码,cd 目录 26 | * ./configure 参数解析,配置安装位置参数,以及其他绑定参数 27 | * make 一般情况下,只需要直接用make即可,但是有时候,生成的Makefile文件中并没有指定C编译器或者C++编译器,那么就需要手动指定了,不然就有可能出现编译错误。 28 | * make install 29 | >安装php时最为复杂,需要根据需要使用的扩展,预先安装一系列的软件支持,然后在./configure中配置软件目录,配置需要开启的扩展等 30 | 31 | 可自行搜索了解详细 32 | ### 集成一键安装 33 | 集成一键安装是通过预先写好的shell脚本,里面包含了安装lnmp所有的命令(编译或软件包安装命令),以及包含了所需扩展的软件包. 34 | 集成一键安装可使用以下几种: 35 | * lnmp集成环境:https://lnmp.org/ 36 | * 宝塔:http://www.bt.cn/ 37 | 可自行搜索了解详细 38 | 39 | -------------------------------------------------------------------------------- /docs/NoobCourse/Linux/Port.md: -------------------------------------------------------------------------------- 1 | ## 端口监控 2 | 在ip章节中,我们知道了,开启一个tcp/udp服务,都得占用一个端口,所有我们可以通过查看端口的方式去判断服务是否开启成功. 3 | 4 | ### netstat命令 5 | 使用netstat命令可查看端口占用情况 6 | netstat命令各个参数说明如下: 7 | * -t : 指明显示TCP端口 8 | * -u : 指明显示UDP端口 9 | * -l : 仅显示监听套接字(所谓套接字就是使应用程序能够读写与收发通讯协议(protocol)与资料的程序) 10 | * -p : 显示进程标识符和程序名称,每一个套接字/端口都属于一个程序。 11 | * -n : 不进行DNS轮询,显示IP(可以加速操作) 12 | ``` 13 | netstat -ntulp |grep 80 14 | ``` 15 | 查看80端口占用情况 16 | 输出: 17 | ``` 18 | tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1036/nginx: master 19 | ``` 20 | 21 | ### lsof命令 22 | lsof命令需要自行安装 23 | ``` 24 | sudo yum install lsof 25 | ``` 26 | 使用方法如下: 27 | ``` 28 | lsof -i tcp #列出所有tcp网络连接 29 | lsof -i udp #列出所有udp网络连接信息 30 | lsof -i :8080 #列出使用8080端口信息 31 | ``` -------------------------------------------------------------------------------- /docs/NoobCourse/Linux/Process.md: -------------------------------------------------------------------------------- 1 | ## 进程管理 2 | 我们可以使用ps 查看当前进程(相当于windows的任务管理器) 3 | ``` 4 | ps -ef |grep php 5 | ``` 6 | 输出: 7 | ``` 8 | root 8351 8346 0 09:07 ? 00:00:00 /usr/bin/php /www/wwwroot/es3_demo/test.php 9 | root 10618 8970 0 14:26 pts/0 00:00:00 grep --color=auto php 10 | ``` 11 | 用于筛选出当前运行中,包含php关键字的进程信息 12 | 通过kill -9 PID可杀死某一个进程: 13 | ``` 14 | kill -9 10618 15 | ``` 16 | 使用killall 可杀死指定名字的进程: 17 | ``` 18 | killall -9 php 19 | ``` 20 | 杀死所有php进程 21 | 22 | >kill 和killall其实是给进程发送一个进程信号的命令,-9是SIGKILL 信号,终止进程,可通过kill ,killall命令发送其他信号 -------------------------------------------------------------------------------- /docs/NoobCourse/NetworkrPotocol/Introduction.md: -------------------------------------------------------------------------------- 1 | ## 网络协议 2 | 网络协议为计算机网络中进行数据交换而建立的规则,标准或约定的集合,所有的计算机/手机等网络设备通信都得遵循网络协议. 3 | 网络协议根据通信的步骤,层级划分为7个层级,从上往下为: 4 | * 应用层 5 | * 表示层 6 | * 会话层 7 | * 传输层 8 | * 网络层 9 | * 数据链路层 10 | * 物理层 11 | 12 | ![图示](networkPotocol.png) 13 | 14 | 15 | 作为php应用程序开发者,我们只需要了解网络层以上的协议即可 -------------------------------------------------------------------------------- /docs/NoobCourse/NetworkrPotocol/ip.md: -------------------------------------------------------------------------------- 1 | ## ip协议(网络层) 2 | 3 | ip协议是互联网的基础协议,它是目前最流行的一种网络协议 4 | 5 | ### 范围 6 | IP的责任就是把数据从源传送到目的地。它不负责保证传送可靠性,流控制,包顺序和其它对于主机到主机协议来说很普通的服务。 7 | 8 | ### 接口 9 | 这个协议由主机到主机协议调用,而此协议负责调用本地网络协议将数据包传送以下一个网关或目的主机。例如TCP可以调用IP协议,在调用时传送目的地址和源地址作为参数,IP形成数据包并调用本地网络(协议)接口传送数据包。 10 | ### 操作 11 | IP实现两个基本功能:寻址和分段。IP可以根据数据包包头中包括的目的地址将数据包传送到目的地址,在此过程中IP负责选择传送的道路,这种选择道路称为路由功能。如果有些网络内只能传送小数据包,IP可以将数据包重新组装并在报头域内注明。IP模块中包括这些基本功能,这些模块存在于网络中的每台主机和网关上,而且这些模块(特别在网关上)有路由选择和其它服务功能。对IP来说,数据包之间没有什么联系,对IP不好说什么连接或逻辑链路。 12 | 13 | IP使用四个关键技术提供服务:服务类型,生存时间,选项和报头校验码。服务类型指希望得到的服务质量。服务类型是一个参数集,这些参数是Internet能够提供服务的代表。这种服务类型由网关使用,用于在特定的网络,或是用于下下一个要经过的网络,或是下一个要对这个数据包进行路由的网关上选择实际的传送参数。生存时间是数据包可以生存的时间上限。它由发送者设置,由经过路由的地方处理。如果未到达时生存时间为零,抛弃此数据包。对于控制函数来说选项是重要的,但对于通常的通信来说它没有存在的必要。选项包括时间戳,安全和特殊路由。报头校验码保证数据的正确传输。如果校验出错,抛弃整个数据包。 14 | 15 | ### ip地址 16 | 把数据从源传送到目的地时,需要有ip地址才能传输,现在ip地址分为ipv4和ipv6 两种地址,现在最常见的就是ipv4地址,例如127.0.0.1(本机地址) 119.75.217.109(百度ip) 17 | 18 | ip传输必须要有明确的ip地址,才能进行数据发送 19 | 20 | >详细内容可自行了解 21 | -------------------------------------------------------------------------------- /docs/NoobCourse/NetworkrPotocol/networkPotocol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/NoobCourse/NetworkrPotocol/networkPotocol.png -------------------------------------------------------------------------------- /docs/NoobCourse/NetworkrPotocol/port.md: -------------------------------------------------------------------------------- 1 | ## 端口 2 | 在网络技术中,端口(Port)包括逻辑端口和物理端口两种类型。物理端口指的是物理存在的端口,如ADSL Modem、集线器、交换机、路由器上用 于连接其他网络设备的接口,如RJ-45端口、SC端口等等。逻辑端口是指逻辑意义上用于区分服务的端口,如TCP/IP协议中的服务端口,端口号的范围从0到65535,比如用于浏览网页服务的80端口,用于FTP服务的21端口等。由于物理端口和逻辑端口数量较多,为了对端口进行区分,将每个端口进行了编号,这就是端口号。本文主要讲逻辑端口. 3 | 4 | ### 逻辑端口 5 | 6 | 端口有什么用呢?我们知道,一台拥有IP地址的主机可以提供许多服务,比如Web服务、FTP服务、SMTP服务等,这些服务完全可以通过1个IP地址来实现。那么,主机是怎样区分不同的网络服务呢?显然不能只靠IP地址,因为IP 地址与网络服务的关系是一对多的关系。实际上是通过“IP地址+端口号”来区 分不同的服务的。 7 | 服务器一般都是通过知名端口号来识别的。例如,对于每个TCP/IP实现来说,FTP服务器的TCP端口号都是21,每个Telnet服务器的TCP端口号都是23,每个TFTP(简单文件传送协议)服务器的UDP端口号都是69。任何TCP/IP实现所提供的服务都用知名的1~1023之间的端口号。这些知名端口号由Internet 号分配机构(InternetAssignedNumbersAuthority,IANA)来管理。 8 | 到1992年为止,知名端口号介于1~255之间。256~1023之间的端口号通常都是由Unix系统占用,以提供一些特定的Unix服务—也就是说,提供一些只有Unix系统才有的、而其他操作系统可能不提供的服务,IANA管理1~1023之间所有的端口号。 9 | Internet扩展服务与Unix特定服务之间的一个差别就是Telnet和Rlogin。它们二者都允许通过计算机网络登录到其他主机上。Telnet是采用端口号为23的TCP/IP标准且几乎可以在所有操作系统上进行实现。Rlogin只是为Unix系统设计的(尽管许多非Unix系统也提供该服务),它的有名端口号为513。 10 | 客户端通常对它所使用的端口号并不关心,只需保证该端口号在本机上是唯一的就可以了。客户端口号又称作临时端口号(即存在时间很短暂)。这是因为它通常只是在用户运行该客户程序时才存在,而服务器则只要主机开着的,其服务就运行。 11 | 大多数TCP/IP实现给临时端口分配1024~5000之间的端口号。大于5000的端口号是为其他服务器预留的(Internet上并不常用的服务)。我们可以在后面看见许多这样的给临时端口分配端口号的例子。 12 | Solaris2.2是一个很有名的例外。通常TCP和UDP的缺省临时端口号从32768开始。 13 | 14 | 15 | ### phper中的端口 16 | 在php开发者中,最常见的就是80 http默认端口了,在通常情况下,我们访问 www.easyswoole.com ,其实是请求的 www.easyswoole.com:80 ,在没有指定端口的情况下,访问网站都是默认为80端口,如果你web服务器监听的是8080端口,访问时就必须 www.easyswoole.com:8080 带上端口才能访问 -------------------------------------------------------------------------------- /docs/NoobCourse/NetworkrPotocol/tcp/http.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/NoobCourse/NetworkrPotocol/tcp/http.jpg -------------------------------------------------------------------------------- /docs/NoobCourse/NetworkrPotocol/tcp/websocket.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/NoobCourse/NetworkrPotocol/tcp/websocket.jpg -------------------------------------------------------------------------------- /docs/NoobCourse/NetworkrPotocol/udp.md: -------------------------------------------------------------------------------- 1 | ## udp(传输层) 2 | UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interconnection,开放式系统互联) 参考模型中一种无连接的传输层协议,提供面向事务的简单不可靠信息传送服务,IETF RFC 768是UDP的正式规范。UDP在IP报文的协议号是17。 3 | 4 | UDP协议全称是用户数据报协议,在网络中它与TCP协议一样用于处理数据包,是一种无连接的协议。在OSI模型中,在第四层——传输层,处于IP协议的上一层。UDP有不提供数据包分组、组装和不能对数据包进行排序的缺点,也就是说,当报文发送之后,是无法得知其是否安全完整到达的。UDP用来支持那些需要在计算机之间传输数据的网络应用。包括网络视频会议系统在内的众多的客户/服务器模式的网络应用都需要使用UDP协议。UDP协议从问世至今已经被使用了很多年,虽然其最初的光彩已经被一些类似协议所掩盖,但是即使是在今天UDP仍然不失为一项非常实用和可行的网络传输层协议。 5 | 6 | 7 | 与所熟知的TCP(传输控制协议)协议一样,UDP协议直接位于IP(网际协议)协议的顶层。根据OSI(开放系统互连)参考模型,UDP和TCP都属于传输层协议。UDP协议的主要作用是将网络数据流量压缩成数据包的形式。一个典型的数据包就是一个二进制数据的传输单位。每一个数据包的前8个字节用来包含报头信息,剩余字节则用来包含具体的传输数据。 8 | 9 | 10 | ### udp与tcp 11 | udp和tcp都属于传输层的协议,都位于ip协议的顶层,他们不同之处有: 12 | * udp是无连接协议,不需要进行tcp的握手 13 | * udp每次发送最大长度是65535,而tcp在握手后可以源源不断的发送 14 | * udp协议使用报头中的校验值来保证数据的安全。校验值首先在数据发送方通过特殊的算法计算得出,在传递到接收方之后,还需要再重新计算。如果某个数据报在传输过程中被第三方篡改或者由于线路噪音等原因受到损坏,发送和接收方的校验计算值将不会相符,由此UDP协议可以检测是否出错。这与TCP协议是不同的,后者要求必须具有校验值。 15 | * udp报文没有可靠性保证、顺序保证和流量控制字段等,可靠性较差。但是正因为udp协议的控制选项较少,在数据传输过程中延迟小、数据传输效率高,适合对可靠性要求不高的应用程序,或者可以保障可靠性的应用程序,如DNS、TFTP、SNMP等。 16 | * 在网络质量令人十分不满意的环境下,UDP协议数据包丢失会比较严重。而tcp会进行确认验证,确保对方接收成功 17 | * udp可实现对网关内的所有主机进行广播 18 | 19 | 20 | ### phper的udp 21 | 在php初级开发者中,是很少接触到udp协议的,常见的有DNS协议, 22 | 在我们输入一个域名时,会先请求到一个dns服务器,由dns服务器匹配出一个ip地址,然后通过ip地址去传输数据, 23 | 在这个步骤中,请求dns服务器使用的就是udp协议 24 | 25 | ### 其他 26 | 具体详细内容可自行搜索了解 -------------------------------------------------------------------------------- /docs/NoobCourse/PHP/Closures.md: -------------------------------------------------------------------------------- 1 | ## 闭包函数 2 | 3 | ### 闭包的概念 4 | 闭包就是能够读取其他函数内部变量的函数。例如在javascript中,只有函数内部的子函数才能读取局部变量,所以闭包可以理解成“定义在一个函数内部的函数“。在本质上,闭包是将函数内部和函数外部连接起来的桥梁。 5 | 在php中,闭包函数一般就是匿名函数. 6 | 举例,有一个定时任务,每一秒执行一次,现在我们要开启一个服务,然后准备在30秒的时候关闭这个服务 7 | ```php 8 | exitServer(); 27 | }); 28 | ``` 29 | 在这里面,使用匿名函数,use了函数外部的$server变量,才使得定时器能回调调用$server->exitServer(); 30 | 31 | 32 | ### 匿名函数 33 | 匿名函数 通俗来讲,就是没有名字的函数,例如上面写的function(){},它通常作为闭包函数使用,使用方法如下: 34 | ```php 35 | 0) { 12 | echo "爸爸先走了,儿子你好好干活\n"; 13 | exit(0); 14 | } else { 15 | while(1){ 16 | echo "1"; 17 | sleep(1); 18 | } 19 | } 20 | ``` 21 | 运行结果: 22 | ![孤儿进程](OrphanProcess.png) 23 | 24 | ### 孤儿进程和僵尸进程 25 | 僵尸进程:一个子进程在其父进程还没有调用wait()或waitpid()的情况下退出。这个子进程就是僵尸进程。任何一个子进程(init除外)在exit()之后,并非马上就消失掉,而是留下一个称为僵尸进程(Zombie)的数据结构,等待父进程处理。这是每个 子进程在结束时都要经过的阶段。如果子进程在exit()之后,父进程没有来得及处理,那么保留的那段信息就不会释放,其进程号就会一直被占用,但是系统所能使用的进程号是有限的,如果大量的产生僵尸进程,将因为没有可用的进程号而导致系统不能产生新的进程. 此即为僵尸进程的危害,应当避免。 26 | 27 | 孤儿进程:一个父进程退出,而它的一个或多个子进程还在运行,那么那些子进程将成为孤儿进程。孤儿进程将被init进程(进程号为1)所收养,并由init进程对它们完成状态收集工作。孤儿进程是没有父进程的进程,孤儿进程这个重任就落到了init进程身上,init进程就好像是一个民政局,专门负责处理孤儿进程的善后工作。每当出现一个孤儿进程的时候,内核就把孤 儿进程的父进程设置为init,而init进程会循环地wait()它的已经退出的子进程。这样,当一个孤儿进程凄凉地结束了其生命周期的时候,init进程就会代表党和政府出面处理它的一切善后工作。因此孤儿进程并不会有什么危害 。 -------------------------------------------------------------------------------- /docs/NoobCourse/PHP/Multiprocess/OrphanProcess.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easy-swoole/doc-old/028b8db1a396342b2a36ce9aece060d3dd2607bf/docs/NoobCourse/PHP/Multiprocess/OrphanProcess.png -------------------------------------------------------------------------------- /docs/NoobCourse/PHP/Multiprocess/ProcessCommunication.md: -------------------------------------------------------------------------------- 1 | ## 进程通信 2 | 在各个进程中,内存空间都是不一致的,各个变量都是在不同的内存空间,举个简单的例子 3 | 4 | >用户A访问服务端,$_SESSION\['user'\]=1; 5 | >用户B同时访问服务端,读取$_SESSION\['user'\]是读取不到的,因为进程之间内存不是相同的 6 | 7 | 同样,在php多进程中,pcntl_fork之后,虽然能读取到之前的变量,但这个变量是复制出来的一份,和原来那份存储位置根本不同,例如: 8 | ```php 9 | 0){ 13 | $str="Tioncico\n";//在主进程修改了$str,不会影响到子进程的$str变量 14 | echo $str; 15 | }elseif ($pid==0){ 16 | echo $str;//$str是pcntl_fork复制出来的 17 | }else{ 18 | 19 | } 20 | ``` 21 | 所以,多进程中根本无法直接通信,那么,该怎么样才能通信呢?可以使用以下几种方式进行通信 22 | 23 | * 管道通信,分为有名管道,无名管道等,可自行搜索了解详细 24 | * 消息队列通信,使用linux消息队列,通过sysvmsg扩展,可查看:http://www.php20.cn/article/137 25 | * 进程信号通信,可查看:http://www.php20.cn/article/134 26 | * 共享内存通信,映射一段能被其他进程所访问的内存,这段共享内存由一个进程创建,但多个进程都可以访问。共享内存是最快的 IPC 方式,它是针对其他进程间通信方式运行效率低而专门设计的。它往往与其他通信机制,如信号两,配合使用,来实现进程间的同步和通信。 27 | * 套接字通信 28 | * 第三方通信,使用文件操作,mysql,redis等方法也可实现通信 29 | 30 | 31 | 可自行搜索了解详细内容 -------------------------------------------------------------------------------- /docs/NoobCourse/PHP/Multiprocess/fork.md: -------------------------------------------------------------------------------- 1 | ## 多进程使用 2 | 怎么才能在一个php脚本中,开启多进程处理呢?这里我们可以使用2种方法(注意,本教程只适用于linux,php-cli环境) 3 | 4 | ### pcntl扩展 5 | pcntl是php官方的多进程扩展,只能在linux环境使用,例如: 6 | ```php 7 | 0){//主进程代码 14 | echo "我是主进程,子进程的pid是{$pid}\n"; 15 | }elseif($pid==0){ 16 | echo "我是子进程,我的pid是".getmypid()."\n"; 17 | }else{ 18 | echo "我是主进程,我现在慌得一批,开启子进程失败了\n"; 19 | } 20 | ``` 21 | 详细内容可自行搜索了解 22 | 23 | ### swoole扩展 24 | swoole扩展是面向生产环境的 PHP 异步网络通信引擎,它也有着进程管理模块 25 | ```php 26 | start();//开启子进程,创建成功返回子进程的PID,创建失败返回false。 35 | echo $str; 36 | if ($pid > 0) {//主进程代码 37 | echo "我是主进程,子进程的pid是{$pid}\n"; 38 | }else{ 39 | echo "我是主进程,我现在不慌了,失败就失败吧\n"; 40 | } 41 | ``` 42 | 详细内容可自行搜索了解 43 | -------------------------------------------------------------------------------- /docs/NoobCourse/RunMode/Introduction.md: -------------------------------------------------------------------------------- 1 | ## 运行模式 2 | php有着5种运行模式,常见的有4种: 3 | 4 | ### cgi 协议模式 5 | cgi模式 通用网关接口(Common Gateway Interface),它允许web服务器通过特定的协议与应用程序通信, 6 | 调用原理大概为: 7 | 用户请求->Web服务器接收请求->fork子进程 调用程序/执行程序->程序返回内容/程序调用结束->web服务器接收内容->返回给用户 8 | 由于每次用户请求,都得fork创建进程调用一次程序,然后销毁进程,所以性能较低 9 | 10 | ### fast-cgi 协议模式 11 | fast-cgi是cgi模式的升级版,它像是一个常驻型的cgi,只要开启后,就可一直处理请求,不再需要结束进程, 12 | 调用原理大概为: 13 | web服务器fast-cgi进程管理器初始化->预先fork n个进程 14 | 用户请求->web服务器接收请求->交给fast-cgi进程管理器->fast-cgi进程管理区接收,给其中一个空闲fast-cgi进程处理->处理完成,fast-cgi进程变为空闲状态,等待下次请求->web服务器接收内容->返回给用户 15 | >注意,fast-cgi和cgi都是一种协议,开启的进程是单独实现该协议的进程 16 | 17 | ### 模块模式 18 | apache+php运行时,默认使用的是模块模式,它把php作为apache的模块随apache启动而启动,接收到用户请求时则直接通过调用mod_php模块进行处理,详细内容可自行百度 19 | 20 | ### php-cli模式 21 | php-cli模式属于命令行模式,对于很多刚开始学php就开始wamp,wnmp的开发者来说是最陌生的一种运行模式 22 | 该模式不需要借助其他程序,直接输入php xx.php 就能执行php代码 23 | 命令行模式和常规web模式明显不一样的是: 24 | * 没有超时时间 25 | * 默认关闭buffer缓冲 26 | * STDIN和STDOUT标准输入/输出/错误 的使用 27 | * echo var_dump,phpinfo等输出直接输出到控制台 28 | * 可使用的类/函数 不同 29 | * php.ini配置的不同 30 | 31 | >想要了解详细内容可查看http://php.net/manual/zh/features.commandline.php 32 | 33 | ### 其他 34 | >本文将以上除了php-cli的模式,都定义为常规web访问模式 35 | -------------------------------------------------------------------------------- /docs/NoobCourse/RunMode/php-fpm.md: -------------------------------------------------------------------------------- 1 | ## php-fpm 2 | PHP-FPM(FastCGI 进程管理器)用于替换 PHP FastCGI 的大部分附加功能,对于高负载网站是非常有用的。 3 | 它的功能包括: 4 | * 支持平滑停止/启动的高级进程管理功能; 5 | * 可以工作于不同的 uid/gid/chroot 环境下,并监听不同的端口和使用不同的 php.ini 配置文件(可取代 safe_mode 的设置); 6 | * stdout 和 stderr 日志记录; 7 | * 在发生意外情况的时候能够重新启动并缓存被破坏的 opcode; 8 | * 文件上传优化支持; 9 | * "慢日志" - 记录脚本(不仅记录文件名,还记录 PHP backtrace 信息,可以使用 ptrace或者类似工具读取和分析远程进程的运行数据)运行所导致的异常缓慢; 10 | * fastcgi_finish_request() - 特殊功能:用于在请求完成和刷新数据后,继续在后台执行耗时的工作(录入视频转换、统计处理等); 11 | * 动态/静态子进程产生; 12 | * 基本 SAPI 运行状态信息(类似Apache的 mod_status); 13 | * 基于 php.ini 的配置文件。 14 | 15 | ### 工作原理: 16 | 它的工作原理大概为: 17 | php-fpm启动->生成n个fast-cgi协议处理进程->监听一个端口等待任务 18 | 用户请求->web服务器接收请求->请求转发给php-fpm->php-fpm交给一个空闲进程处理 19 | ->进程处理完成->php-fpm返回给web服务器->web服务器接收数据->返回给用户 20 | 21 | >nginx+php-fpm 就是用的以上的方法 -------------------------------------------------------------------------------- /docs/NoobCourse/Sync.md: -------------------------------------------------------------------------------- 1 | 2 | ## 同步 3 | 同步代码主要是指调用某个逻辑时,会等待到该逻辑返回调用结果. 4 | 例如: 5 | ```php 6 | select();//伪代码,查询数据库 9 | sleep(3);//伪代码,当成执行了3秒才返回 10 | echo json_encode($result);//返回数据 11 | ``` 12 | 只有当select查询到数据时,才会返回数据给$result,这个值一定是数据库操作完毕返回的值 13 | 14 | 例如: 15 | ```php 16 | 3, 19 | CURLOPT_TIMEOUT=>10, 20 | CURLOPT_AUTOREFERER=>true, 21 | CURLOPT_USERAGENT=>"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)", 22 | CURLOPT_FOLLOWLOCATION=>true, 23 | CURLOPT_RETURNTRANSFER=>true, 24 | CURLOPT_SSL_VERIFYPEER=>false, 25 | CURLOPT_SSL_VERIFYHOST=>false, 26 | CURLOPT_HEADER=>true, 27 | ); 28 | curl_setopt_array($ch,$curlOPt); 29 | $result = curl_exec($ch); 30 | var_dump(curl_error($ch)); 31 | curl_close($ch); 32 | }; 33 | 34 | $a(); 35 | 36 | if(pcntl_fork()){ 37 | $a(); 38 | }else{ 39 | $a(); 40 | } 41 | 42 | ``` 43 | ::: warning 44 | swoole中同理。 45 | ::: 46 | 47 | 48 | ## 解决方案 49 | 更新libcurl至最新的7.5.x,并重新编译php curl拓展。 50 | 查看拓展版本: 51 | ``` 52 | php --ri curl 53 | ``` 54 | 55 | -------------------------------------------------------------------------------- /docs/Other/random.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 随机生成问题 3 | meta: 4 | - name: description 5 | content: easyswoole,随机生成问题 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|随机生成问题 8 | --- 9 | ## 随机生成问题 10 | 11 | 由于Swoole本身的原因,在使用随机数时,需要额外注意,如果在父进程内调用了`mt_rand`,不同的子进程内再调用`mt_rand`返回的结果会是相同的。所以必须在每个子进程内调用`mt_srand`重新播种。 12 | 13 | ::: warning 14 | `shuffle`和`array_rand`等依赖随机数的`PHP`函数同样会受到影响 15 | ::: 16 | 17 | 18 | ## 场景例子 19 | 20 | 在异步任务,异步进程中,都需要注意随机数播种的问题,如下面的例子 21 | 22 | ```php 23 | mt_rand(0, 1); // 此处调用了 mt_rand 已经在父进程内自动播种 24 | $worker_num = 16; 25 | 26 | // fork 进程 27 | for ($i = 0; $i < $worker_num; $i++) { 28 | $process = new swoole_process('child_async', false, 2); 29 | $pid = $process->start(); 30 | } 31 | 32 | function child_async(swoole_process $worker) 33 | { 34 | mt_srand(); // 此处 必须要重新播种 否则会得到相同的结果 35 | echo mt_rand(0, 100) . PHP_EOL; 36 | $worker->exit(); 37 | } 38 | ``` 39 | 40 | -------------------------------------------------------------------------------- /docs/Other/redisSubscribe.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 自定义进程实现redis订阅 3 | meta: 4 | - name: description 5 | content: easyswoole,自定义进程实现redis订阅 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|自定义进程实现redis订阅 8 | --- 9 | 10 | ## 自定义进程实现redis订阅 11 | ## 实现代码 12 | ```php 13 | connect('127.0.0.1'); 34 | $redis->subscribe(['ch1'],function (){ 35 | var_dump(func_get_args()); 36 | }); 37 | } 38 | 39 | public function onShutDown() 40 | { 41 | // TODO: Implement onShutDown() method. 42 | } 43 | 44 | public function onReceive(string $str, ...$args) 45 | { 46 | // TODO: Implement onReceive() method. 47 | } 48 | 49 | } 50 | ``` 51 | 52 | 接下来,需要做的事情,就是到EasySwooleEvent.php的主服务创建事件中,注册该进程即可。 53 | ```php 54 | use App\Process; 55 | use EasySwoole\Core\Swoole\Process\ProcessManager; 56 | 57 | ServerManager::getInstance()->getSwooleServer()->addProcess((new Subscribe('sub'))->getProcess()); 58 | ``` 59 | -------------------------------------------------------------------------------- /docs/Other/traitSingleTon.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Trait与单例 3 | meta: 4 | - name: description 5 | content: easyswoole,Trait与单例 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|Trait与单例 8 | --- 9 | 10 | ## Trait与单例 11 | 12 | ```php 13 | 14 | trait A{ 15 | private static $instance; 16 | static function getInstance() 17 | { 18 | if(!isset(self::$instance)){ 19 | self::$instance = new static(); 20 | } 21 | return self::$instance; 22 | } 23 | } 24 | 25 | class B{ 26 | use A; 27 | function a() 28 | { 29 | var_dump('call at B'); 30 | } 31 | } 32 | 33 | class C extends B{ 34 | function a() 35 | { 36 | var_dump('call at c'); 37 | parent::a(); // TODO: Change the autogenerated stub 38 | } 39 | } 40 | 41 | class D extends B{ 42 | use A; 43 | function a() 44 | { 45 | var_dump('call at D'); 46 | parent::a(); // TODO: Change the autogenerated stub 47 | } 48 | } 49 | $b = B::getInstance(); 50 | $c = C::getInstance(); 51 | $d = D::getInstance(); 52 | 53 | $c->a(); 54 | $d->a(); 55 | 56 | ``` 57 | 58 | 以上输出: 59 | ```php 60 | string(9) "call at B" 61 | string(9) "call at D" 62 | string(9) "call at B" 63 | 64 | ``` 65 | -------------------------------------------------------------------------------- /docs/Preface/componentUpdateLog.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 组件更新记录 3 | meta: 4 | - name: description 5 | content: easyswoole组件更新记录 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|组件更新记录|框架更新 8 | --- 9 | 10 | # 2019-12 11 | 12 | ## 新增 13 | 14 | - [#57](https://github.com/easy-swoole/orm/pull/57) `ORM` 增加 `invoke`支持,发布版本`1.2.1` 15 | - [#38](https://github.com/easy-swoole/mysqli/pull/38) `Mysqli` raw自定义语句支持`参数绑定` 16 | 17 | ## 修改 18 | - [#3](https://github.com/easy-swoole/jwt/pull/3) `Jwt` 删除 `algMethod`方法,统一使用`setAlg` 19 | 20 | # 2019-10 21 | 22 | ## 新增 23 | - [#14](https://github.com/easy-swoole/orm/pull/14) `ORM` 增加 `连贯操作`、`聚合查询` 24 | - [#19](https://github.com/easy-swoole/orm/pull/19) `ORM` 增加 `alias连贯操作支持`、`支持`直接获取join等不在定义表结构中的数据、`get方法增加第二个参数returnAsArray` 25 | -------------------------------------------------------------------------------- /docs/Preface/contactAuthor.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 联系作者 3 | meta: 4 | - name: description 5 | content: 联系easyswoole作者 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|easyswoole联系我们|easyswoole作者 8 | --- 9 | # 联系作者 10 | 11 | - 作者微信 12 | 13 | ![](/resources/authWx.png) 14 | 15 | - 商业支持: 16 | - QQ 291323003 17 | - EMAIL admin@fosuss.com 18 | 19 | - QQ交流群 20 | - VIP群 579434607 (本群需要付费599元) 21 | - EasySwoole官方一群 633921431(已满) 22 | - EasySwoole官方二群 709134628(已满) 23 | - EasySwoole官方三群 932625047 24 | -------------------------------------------------------------------------------- /docs/Preface/donation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 捐赠 3 | meta: 4 | - name: description 5 | content: easyswoole捐赠 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|easyswoole|捐赠|easyswoole 8 | --- 9 | 10 | # 捐赠 11 | 您的捐赠是对EasySwoole项目开发组最大的鼓励和支持。我们会坚持开发维护下去。 您的捐赠将被用于: 12 | 13 | - 持续和深入地开发 14 | - 文档和社区的建设和维护 15 | ## 支付宝 16 | ![捐赠](/resources/donate.png) 17 | 18 | ::: warning 19 | 支付宝二维码支持花呗、信用卡分期付款 20 | ::: 21 | 22 | ## 微信 23 | ![捐赠](/resources/wx_donate.png) 24 | 25 | 26 | ::: warning 27 | 通过微信捐赠的用户,请捐赠时留言您的名字,否则不知道您的大名 28 | ::: 29 | 30 | ## 捐赠者列表 31 | - *章进 32 | - *晓博 33 | - *振宇 34 | - *高明 35 | - *东东 36 | - *佳明 37 | - *亮亮 38 | - *凯峰 39 | - *进国 40 | - *海旋 41 | - *志军 42 | - *成龙 43 | - *玲杰 44 | - *东杰 45 | - *鹏 46 | - *力 47 | - *宾 48 | - *海伟 49 | - *勇辉 50 | - *思杰 51 | - *龙翔 52 | - *洋 53 | - *伟平 54 | - *坤平 55 | - *勇城 56 | - *锐 57 | - *昆标 58 | - *浩斌 59 | - *博文 60 | - *苏维 61 | - *海涛 62 | - *志成 63 | - *磊 64 | - *凯 65 | - *建军 66 | - *浩 67 | - *永健 68 | - *志强 69 | - *少峰 70 | - *坤磊 71 | - *国锴 72 | - *祖兴 73 | - *宇翔 74 | 75 | 76 | 77 | ::: warning 78 | 以上名单为按照时间排序,与捐赠金额无关(多次捐赠者未避免重复也只写一次),如果您不希望出现在该列表,或者是被遗漏了,请与291323003@qq.com联系。 79 | ::: 80 | -------------------------------------------------------------------------------- /docs/Preface/team.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 文档维护团队 3 | meta: 4 | - name: description 5 | content: EasySwoole开源团队,文档维护团队介绍,EasySwoole社区 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole | EasySwoole开源团队 | EasySwoole社区 | 文档维护团队 8 | --- 9 | 10 | 11 | # 共建EasySwoole社区计划 12 | 13 | 邀您加入EasySwoole社区维护团队 14 | 15 | 你能获得 16 | 17 | - EasySwoole相关问题的指导 18 | - EasySwoole贡献者标识 19 | - Swoole相关的基础知识指导 20 | 21 | 我们希望你能 22 | 23 | - 查找EasySwoole文档中的问题 24 | - 反馈EasySwoole文档中的问题 25 | - 编写和修改EasySwoole文档 26 | - 维护社区系统内容 27 | 28 | # 加入我们 29 | 30 | 联系宣言 31 | 32 | - QQ: 59419979 33 | - Email: 59419979@qq.com 34 | 35 | 36 | # 文档维护团队 37 | 38 | ::: tip 39 | 排名不分先后 40 | ::: 41 | 42 | - 闹钟 1433050430@qq.com 43 | - 只饮半盏 907274166@qq.com 44 | - 小林 1450948930@qq.com 45 | - C君 386273094@qq.com 46 | - 十六 3930240@qq.com 47 | 48 | -------------------------------------------------------------------------------- /docs/Socket/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: EasySwoole Socket 3 | meta: 4 | - name: description 5 | content: EasySwoole Socket,swoole tcp, swoole websocket, swoole udp,php websocket 6 | - name: keywords 7 | content: swoole|swoole 拓展|swoole 框架|EasySwoole Socket|swoole tcp| swoole websocket| swoole udp|php websocket 8 | --- 9 | 10 | ## 如何遍历全部链接 11 | ```php 12 | use EasySwoole\EasySwoole\ServerManager; 13 | $server = ServerManager::getInstance()->getSwooleServer(); 14 | $start_fd = 0; 15 | while(true) 16 | { 17 | $conn_list = $server->getClientList($start_fd, 10); 18 | if ($conn_list===false or count($conn_list) === 0) 19 | { 20 | echo "finish\n"; 21 | break; 22 | } 23 | $start_fd = end($conn_list); 24 | var_dump($conn_list); 25 | foreach($conn_list as $fd) 26 | { 27 | $server->send($fd, "broadcast"); 28 | } 29 | } 30 | ``` 31 | 32 | 33 | ::: warning 34 | https://wiki.swoole.com/wiki/page/p-connection_list.html 35 | ::: 36 | 37 | ## 如何获取链接信息 38 | 39 | ```php 40 | use EasySwoole\EasySwoole\ServerManager; 41 | $server = ServerManager::getInstance()->getSwooleServer(); 42 | $fdinfo = $server->getClientInfo($fd); 43 | ``` 44 | 45 | ::: warning 46 | https://wiki.swoole.com/wiki/page/p-connection_info.html 47 | ::: 48 | 49 | ## Socket有哪些开发场景? 50 | 51 | ### h5即时游戏 52 | 53 | ### 网页聊天室 54 | 55 | ### 物联网开发 56 | 57 | ### 服务器udp广播 58 | 59 | ### 车联网 60 | 61 | ### 智能家居 62 | 63 | ### web网页服务器 64 | -------------------------------------------------------------------------------- /docs/Video/404.md: -------------------------------------------------------------------------------- 1 | # 搬运中! -------------------------------------------------------------------------------- /git-pull.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | while ((1)) 3 | do 4 | sleep 30; 5 | git pull; 6 | done 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "easyswoole", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "docs:dev": "vuepress dev docs", 8 | "docs:build": "vuepress build docs" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "vuepress": "^1.2.0" 14 | } 15 | } 16 | --------------------------------------------------------------------------------