Yaf 命令行模式爬坑
前言
使用 yaf 框架做一个消息队列,执行命令的时候一直找不到对应的控制器,爬坑2小时,原来是Git Bash
的锅。
开发环境
windwos 10
问题重现
/root_path/shell/index.php
<?php
if (empty($argv[1])) {
exit('command error');
}
ini_set('display_errors', 'on');
error_reporting(E_ALL);
define('IS_CLI', true);
define('APP_PATH', realpath(__DIR__.'/../'));
date_default_timezone_set('Asia/Shanghai');
require_once APP_PATH.'/vendor/autoload.php';
$app = new Yaf_Application(APP_PATH.'/conf/application.ini', 'common');
$app->bootstrap()->getDispatcher()->dispatch(new Yaf_Request_Simple());
在Git Bash
中执行命令php index.php request_uri=/cli/Notify/login
输出如下
Failed opening controller script D:\wnmp\www\bitell\Middleman/app\controllers\:.php: No such file or directory
将index.php
改成这样
<?php
$request = new Yaf_Request_Simple();
print_r($request);
die;
再执行命令 php index.php request_uri=/cli/Notify/login
输出如下
Yaf_Request_Simple Object
(
[module] =>
[controller] =>
[action] =>
[method] => CLI
[params:protected] => Array
(
)
[language:protected] =>
[_exception:protected] =>
[_base_uri:protected] =>
[uri:protected] => :/Program Files/Git/cli/Notify/login
[dispatched:protected] =>
[routed:protected] =>
)
uri
寻找 Git Bash
的安装目录去了,所以找不到我的控制器了
在 Windows PowerShell
中 执行命令 php index.php request_uri=/cli/Notify/login
输出如下
Yaf_Request_Simple Object
(
[module] =>
[controller] =>
[action] =>
[method] => CLI
[params:protected] => Array
(
)
[language:protected] =>
[_exception:protected] =>
[_base_uri:protected] =>
[uri:protected] => cli/Notify/login
[dispatched:protected] =>
[routed:protected] =>
)
还原index.php
就可以正常使用了,爬出来了
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: