Skip to content

Instantly share code, notes, and snippets.

@luxixing
luxixing / 属性(properties).md
Last active August 29, 2015 14:01
YII2 框架关键概念

属性

在PHP里,类的成员变量也被称之为属性,这些变量是类定义的一部分,被用来表示类实例的状态(区分不同类实例)。在具体的实践中,你可能要经常处理可读或者可写属性的特殊方式,举个例子, 你可能想要给属性$label赋值一个字符串,但是这个字符串必须使用trim函数过滤开头结尾的空格,为了完成这个特殊处理你可能需要使用如下代码

$object->label = trim($label);

上述代码的缺点是,凡是在给label属性赋值的时候,你都必须使用trim函数去处理。假设在以后label属性的首字母必须大写,那么凡是给label属性赋值的代码,就必须被修改。你应该尽可能的避免这种代码重复。

@luxixing
luxixing / CentOS 6.5下PHP-6.4编译安装.md
Last active August 29, 2015 14:13
CentOS 6.5下PHP-6.4编译安装

####编译前执行下列命令####

#添加组
groupadd www
#添加php-fpm用户
useradd -c php-fpm-user -g www -M php-fpm

# c和c++编译器
yum install -y gcc gcc-c++
@luxixing
luxixing / cmd.sh
Created June 22, 2013 15:31
一些常用sh命令收集
#将本地生成的公匙写入到远端服务器的验证文件中,实现无密码登录
cat ~/.ssh/id_rsa.pub | ssh user@host "cat - >> ~/.ssh/authorized_keys"
#生成ssh密匙命令在当前用户家目录
ssh-keygen
#显示系统有多少用户
cat /etc/passwd | cut -d: -f1
#ssh登陆之后执行一个命令
ssh -t root@10.1.1.169 "cd /data ; bash"
@luxixing
luxixing / php-configure.sh
Created June 23, 2013 02:27
php编译选项 报错一般就是扩展依赖的库不存在,查找并且安装即可
./configure\
--with-config-file-path=/usr/local\
--with-config-file-path=/usr/local/etc/php\
--enable-fpm\
--with-fpm-user=php-fpm\
--with-fpm-group=php-fpm\
--enable-mysqlnd\
--with-mysqli\
--with-pdo-mysql\
--with-mysql=mysqlnd\
<?php
// No, Thanks. Direct file access forbidden.
! defined( 'ABSPATH' ) AND exit;
// INIT
add_action( 'after_setup_theme', array( 'unavailable_post_status', 'init' ) );
class unavailable_post_status extends wp_custom_post_status
{
/**
@luxixing
luxixing / audition.php
Last active December 19, 2015 18:19
面试题答案
1 打印前一天时间
<?php
echo date("Y-m-d H:i:s", strtotime("-1 days"));
?>
2 过滤html代码
如果此题单纯值的html代码,则 htmlspecialchars($str),处理输入存储
如果包含用户输入过滤,则sql语句防注入,过滤关键词,使用pdo的时候prepare sql语句 ' 转义
还有和谐社会的关键词过滤(这个非技术而属于政治了)
php 原生 Filler 族函数能做相当一部分工作,可在此基础上扩展一个过滤类
@luxixing
luxixing / nginx-confgiure.sh
Created July 26, 2013 11:07
nginx 编译安装选项 google 的工具单独安装
./configure --prefix=/usr/local\
--conf-path=/usr/local/etc/nginx/\
--user=nginx\
--group=www\
--with-http_ssl_module\
--with-http_realip_module\
--with-http_gunzip_module\
--with-google_perftools_module
@luxixing
luxixing / nginx-startup.sh
Created August 6, 2013 10:44
nginx 开启启动脚本
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
@luxixing
luxixing / mysl-init-script.sh
Created August 7, 2013 01:46
mysql install after run the init-db shell script
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql-5.6.13/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql-5.6.13/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
@luxixing
luxixing / 常见问题碎片
Created August 15, 2013 03:17
常见问题汇总
1 php json_encode
假设encode编码的源数据是 : array(1,2,3,4,5,5),那么json_encode的结果是数组
假设encode编码的源数据是:array(1=>1,2=>3),那么json_encode的结果是对象
json_encode默认把关联数组编码为对象
这个细节在和前端js交互传递数据的时候非常重要