Heim > php教程 > php手册 > Hauptteil

如何在YAF中使用命令行(Cli模式-yaf2.1.17)

WBOY
Freigeben: 2016-06-06 20:07:20
Original
2987 Leute haben es durchsucht

Part 1. 上周yaf群里的几位同学提出不解如何在yaf中使用cli模式。 正巧我现在的项目中用到了yaf的cli模式去做守护进程。其实在鸟哥的yaf doc中已经写的很明白。 今天主要还是用实际例子来演示一下,已会者可绕道。 在yaf中用到命令行大多是为了跑Crontab或者

  Part 1. 上周yaf群里的几位同学提出不解如何在yaf中使用cli模式。 正巧我现在的项目中用到了yaf的cli模式去做守护进程。其实在鸟哥的yaf doc中已经写的很明白。 今天主要还是用实际例子来演示一下,已会者可绕道。 在yaf中用到命令行大多是为了跑Crontab或者Daemon。 其实yaf doc已经很的很明白了。这篇只是为大家详解一下。 首先,为了更好的与web区分(配置文件,argc、argv判断等等).重新创建一个入口文件是比较好的做法。 $app = new \Yaf\Application(APP_PATH . "/conf/application.ini"); $app->getDispatcher()->dispatch(new \Yaf\Request\Simple());   这样入口文件就完成了。 接下来,你需要学会yaf命令行的调用方法。来一个示例。   php cli.php request_uri="/daemon/start" Yaf_Request_Simple的构造函数可以不接受任何参数, 在这种情况下, Yaf_Request_Simple会在命令行参数中, 寻找一个字符串参数, 如果找到, 则会把请求的request_uri置为这个字符串.   request_uri=”/daemon/start” 中的路径便是Controller的路由路径. 在例子里指向/Controller/Daemon.php 中的 startAction().   Part 2. 经过鸟哥提醒,才知道还有一种方法,通过Yaf_Application::execute(..)去实现。 先看一下这个函数的定义: ? ?public?void?Yaf_Application::execute?(?callable?$entry?,?string?$...?) This method is typically used to run Yaf_Application in a [...]
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!