分类目录归档:code

php-fpm 5.3.3 rpm package with root privileges for centos/redhat 6

出于安全的考虑从源里面安装的php-fpm是不允许以root权限运行的

ERROR: [pool www] please specify user and group other than root

但是有些时候确实需要root权限,可以使用我打的开放root版本

php-fpm-5.3.3-1.i_want_root.el6.i386.rpm
php-fpm-5.3.3-1.i_want_root.el6.x86_64.rpm

如果想打其他php版本的包,可以修改下面的脚本使用

#!/bin/sh
yum install rpm-build gcc make subversion wget
yum install bzip2-devel gmp-devel zlib-devel pcre-devel libxml2-devel openssl-devel
test ! -f ./autoconf-2.13-8.noarch.rpm && wget "http://rpm.bluehua.org/php-fpm/autoconf-2.13-8.noarch.rpm"
rpm -e autoconf
rpm -ivh ./autoconf-2.13-8.noarch.rpm
#修改源码版本
test ! -f ./php-5.3.3.tar.bz2 && wget "http://museum.php.net/php5/php-5.3.3.tar.bz2"
tar jxvf ./php-5.3.3.tar.bz2
cd php-5.3.3/
rm -rf ./sapi/fpm/
#选择适当的php-fpm版本
svn co http://svn.php.net/repository/php/php-src/branches/PHP_5_3_10/sapi/fpm/ ./sapi/fpm
./buildconf --force
test ! -f ./php-fpm-build-rpm.tar.gz && wget "http://rpm.bluehua.org/php-fpm/php-fpm-build-rpm.tar.gz"
tar zxvf ./php-fpm-build-rpm.tar.gz
#修改php-fpm.spec中的版本号
rpmbuild -bb ./php-fpm.spec

一个函数搞定PHP调试日志

对,你没有看错,不是syslog,也不是一坨class,一个函数搞定。。。
—————————-
今天有个搞C++同事问我PHP怎么打印日志,于是贴了他一个函数,绝对实用~
https://gist.github.com/emptyhua/5055043

function debug_log() {
    if (false) return; //开关
    static $fp = 0;
    if ($fp === 0) {
        $logname = 'myprojectname';//日志名称
        $fp = fopen('/tmp/' . $logname . '.debug.log', 'a');
    } 
    $traces = debug_backtrace();
    $trace = count($traces) > 1 ? $traces[1] : $traces[0];
    $log_msg = date('Y-m-d H:i:s') . ' FILE:' . basename($trace['file']) . ' FUNC:' . $trace['function'] . ' LINE:' . $trace['line'] . ' :' . "\n";
    foreach(func_get_args() as $arg) {
        if (is_string($arg)) {
            $log_msg .= $arg . ' ';
        } else {
            $log_msg .= var_export($arg, true) . ' ';
        }
    }
    fwrite($fp, $log_msg . "\n");
}
debug_log('队列ID:', $queue_id, '内容:', $task_infos);
2013-02-28 16:53:40 FILE:task.inc.php FUNC:_get_locate_task LINE:347
队列ID: locate337512971_taskqueue 内容: array (
)

backup:批量的顺序编辑文件

实践证明,不记一下,一个错误真的会犯n次都不长记性。。。之前shell备份里已有笨办法一个

find -name "*.php"|xargs grep -l "<script"|sudo xargs sudo vim

报错:

Vim: Warning: Input is not from a terminal

原因:http://stackoverflow.com/questions/3852616/xargs-with-command-that-open-editor-leaves-shell-in-weird-state
The problem is that since you’re running xargs (and hence git and hence vim) in a pipeline, its stdin is taken from the output of cat projectPaths rather than the terminal; this is confusing vim. Fortunately, the solution is simple: add the -o flag to xargs, and it’ll start git (and hence vim) with input from /dev/tty, instead of its own stdin.

backup:展开文件路径中的通配符

python:

import glob
for input_file in glob.iglob(sys.argv[1]):
    for root, dirs, files in os.walk(input_file):
        for file in files:
            if file.endswith('.js') and not file.endswith('.min.js'):
                process_static_file(os.path.join(root, file))
            elif file.endswith('.css'):
                process_static_file(os.path.join(root, file))

php:

foreach (glob("*.txt") as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}

node.js:
https://github.com/isaacs/node-glob

var glob = require("glob")
 
// options is optional
glob("**/*.js", options, function (er, files) {
  // files is an array of filenames.
  // If the `nonull` option is set, and nothing
  // was found, then files is ["**/*.js"]
  // er is an error object or null.
})