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版本参考官方文档

zendstudio 使用外部composer

系统:

MacOS 10.12.6

ZendStudio 使用外部composer有个讲究,应该使用/usr/local/Cellar/composer/1.4.2/libexec/composer.phar文件而不应该使用/usr/local/Cellar/composer/1.4.2/libexec/composer,因为composer是个shell脚本,会干一些事情,比如定义环境变量等等,会导致一系列的错乱,例如下面的错误:

Failed loading /Applications/Zend Studio.app/Contents/Eclipse/plugins/com.zend.php.executables.macosx_7.1.3.201703171134/resources/ext/ZendDebugger.so:  dlopen(/Applications/Zend Studio.app/Contents/Eclipse/plugins/com.zend.php.executables.macosx_7.1.3.201703171134/resources/ext/ZendDebugger.so, 9): Library not loaded: /usr/local/openssl-1.0.2k/lib/libssl.1.0.0.dylib
  Referenced from: /Applications/Zend Studio.app/Contents/Eclipse/plugins/com.zend.php.executables.macosx_7.1.3.201703171134/resources/ext/ZendDebugger.so
  Reason: image not found

由于使用composer脚本导致/usr/local/openssl-1.0.2k/lib/libssl.1.0.0.dylib找不到,正确位置应该是:

/Applications/Zend Studio.app/Contents/Eclipse/plugins/com.zend.php.executables.macosx_7.1.3.201703171134/resources/libssl.1.0.0.dylib

使用composer.phar解决问题。

ps:使用外部composer和中国镜像会有一系列的好处。