php在线更新svn

如果没有服务器权限,比如前端开发人员,可以用PHP做一个从svn上线的http接口。

    function svnupAction()
    {
        $encoding = 'export LC_ALL=en_US.UTF-8;export LANG=en_US.UTF-8;export LANGUAGE=en_US.UTF-8;';
        $out = '<pre>';
        $dir = Application::app()->getAppDirectory() . '/../data/svn/default';
        $path = Application::app()->getAppDirectory() . '/../public';
        $p = $this->getRequest()->getQuery('path', '');
        if (! empty($p)) {
            $path .= '/' . $p;
        }
        $out .= shell_exec(
            $encoding . '/usr/bin/svn up --config-dir=' . $dir . ' ' . $path .
                 ' 2>&1');
        $out .= '</pre>';
        echo $out;
        return false;
    }

需要提前在对应目录生成记住密码的svn配置

sudo -u apache export LC_ALL=en_US.UTF-8;export LANG=en_US.UTF-8;export LANGUAGE=en_US.UTF-8;/usr/bin/svn up --config-dir=/srv/www/xxx/app/../data/svn/default /srv/www/xxx/app/../public 2>&1

 

php slim 命令行(cli)运行

只需要mock环境变量即可

$settings = require __DIR__ . '/../src/settings.php';
if (PHP_SAPI == 'cli') {
    global $argv;
    $env = [];
    if (isset($argv[2])) {
        $env['REQUEST_METHOD'] = $argv[2];
    }
    $env['REQUEST_URI'] = $argv[1];
    $settings['environment'] = \Slim\Http\Environment::mock($env);
}
$app = new App($settings);

命令行的第一个参数就是uri,第二个参数是method

PHP各版本XHProf

扩展

<php 7
https://pecl.php.net/package/xhprof
https://github.com/phacility/xhprof/tree/master/extension

>=php 7
https://github.com/tideways/php-profiler-extension (https://tideways.io/profiler/xhprof-for-php7-php5.6)
https://github.com/longxinH/xhprof

UI

https://github.com/phacility/xhprof

composer

https://github.com/PBWebMedia/xhprof

php.ini

auto_prepend_file = xhprof.php
xhprof.output_dir = /path/to/xhprof/run
tideways版本参考官方文档