升东运维是一家专业从事Linux/Freebsd Unix/Windows平台网站维护业务的公司,专业提供Linux(CentOS Redhat Ubuntu等),Unix(Freebsd),Nginx,Apache等系统及网站维护,七年从业经验

Posts Tagged ‘php’

PHP5.4发布

星期日, 三月 4th, 2012

PHP 5.4.0 Release Announcement

The PHP development team is proud to announce the immediate availability of PHP 5.4.0. This release is a major leap forward in the 5.x series, and includes a large number of new features and bug fixes. The key features of PHP 5.4.0 include:

  • New language syntax including Traitsshortened array syntax and more
  • Improved performance and reduced memory consumption
  • Support for multibyte languages now available in all builds of PHP at the flip of a runtime switch
  • Built-in webserver in CLI mode to simplify development workflows and testing
  • Cleaner code base thanks to the removal of multiple deprecated language features
  • Many more improvements and fixes

Changes that affect compatibility:

Extensions moved to PECL:

PHP 5.4 will be the last series to support Windows XP and Windows 2003. We will not provide binary packages for these Windows versions after PHP 5.4. For users upgrading from PHP 5.3 there is a migration guide available here, detailing the changes between PHP 5.3 and PHP 5.4.0. For a full list of changes in PHP 5.4.0, see the ChangeLog.

Freebsd9.0安装Nginx+PHP-FPM+MySQL+eAccelerator+Memcached

星期三, 一月 25th, 2012

本博客在freebsd9.0 x64下安装成功 软件版本 php5.3.10,mysql5.5,nginx1.0.11  后续版本可能有所变化,请根据实际情况自己修改

(如果机器性能可以,整个编译过程预计耗时4个小时,当然如果网速慢,那就是半天甚至一天了,本博客是预先下载了所有编译的源代码到/usr/ports/distfiles,详细列表会贴在本文最后)

安装前务必校验系统时间及时区(ntpdate time.windows.com),否则安装过程会出错,出错时make clean清理一下,校对时间再次编译即可

更新 ports

第一种方式: portsnap (自带)

首先修改/etc/portsnap.conf

SERVERNAME=portsnap.cn.freebsd.org

  1. 下载压缩的 Ports 套件快照到 /var/db/portsnap
    # portsnap fetch
  2. 假如是首次运行 Portsnap, 则需要将快照释放到 /usr/ports
    # portsnap extract

    如果您已经有装好的 /usr/ports 而只想更新, 则应执行下面的命令:

    # portsnap update

第二种方式 首先安装 cvsup,更新ports (如果用上面的方式 此步跳过!)

# fetch ftp://ftp.freebsd.org/pub/FreeBSD/ports/packages/All/cvsup-without-gui-16.1h_4.tbz
# pkg_add cvsup-without-gui-16.1h_4.tbz

完成后需要退出终端重新登陆。

复制cvsup更新配置文件

# cp /usr/share/examples/cvsup/ports-supfile /etc/supfile

下面是我使用的配置,屏蔽了desktop等一些服务器用不到的软件包,源已经改成中国镜像,速度比国外的主服务器要快很多

# $FreeBSD: release/9.0.0/share/examples/cvsup/ports-supfile 219858 2011-03-22 04:31:35Z glebius $
#
# This file contains all of the “CVSup collections” that make up the
# FreeBSD-current ports collection.
#
# CVSup (CVS Update Protocol) allows you to download the latest CVS
# tree (or any branch of development therefrom) to your system easily
# and efficiently (far more so than with sup, which CVSup is aimed
# at replacing). If you’re running CVSup interactively, and are
# currently using an X display server, you should run CVSup as follows
# to keep your CVS tree up-to-date:
#
# cvsup ports-supfile
#
# If not running X, or invoking cvsup from a non-interactive script, then
# run it as follows:
#
# cvsup -g -L 2 ports-supfile
#
# You may wish to change some of the settings in this file to better
# suit your system:
#
# host=CHANGE_THIS.FreeBSD.org
# This specifies the server host which will supply the
# file updates. You must change it to one of the CVSup
# mirror sites listed in the FreeBSD Handbook at
# http://www.freebsd.org/doc/handbook/cvsup.html#CVSUP-MIRRORS.
# You can override this setting on the command line
# with cvsup’s “-h host” option.
#
# base=/var/db
# This specifies the root where CVSup will store information
# about the collections you have transferred to your system.
# A setting of “/var/db” will generate this information in
# /var/db/sup. You can override the “base” setting on the
# command line with cvsup’s “-b base” option. This directory
# must exist in order to run CVSup.
#
# prefix=/usr
# This specifies where to place the requested files. A
# setting of “/usr” will place all of the files requested
# in “/usr/ports” (e.g., “/usr/ports/devel”, “/usr/ports/lang”).
# The prefix directory must exist in order to run CVSup.

# Defaults that apply to all the collections
#
# IMPORTANT: Change the next line to use one of the CVSup mirror sites
# listed at http://www.freebsd.org/doc/handbook/cvsup.html#CVSUP-MIRRORS.
*default host=cvsup.cn.FreeBSD.org
*default base=/var/db
*default prefix=/usr
*default release=cvs tag=.
*default delete use-rel-suffix

# If you seem to be limited by CPU rather than network or disk bandwidth, try
# commenting out the following line. (Normally, today’s CPUs are fast enough
# that you want to run compression.)
*default compress

## Ports Collection.
#
# The easiest way to get the ports tree is to use the “ports-all”
# mega-collection. It includes all of the individual “ports-*”
# collections,
#ports-all

# These are the individual collections that make up “ports-all”. If you
# use these, be sure to comment out “ports-all” above.
#
# Be sure to ALWAYS cvsup the ports-base collection if you use any of the
# other individual collections below. ports-base is a mandatory collection
# for the ports collection, and your ports may not build correctly if it
# is not kept up to date.
ports-base
#ports-accessibility
#ports-arabic
ports-archivers
#ports-astro
#ports-audio
ports-benchmarks
#ports-biology
#ports-cad
#ports-chinese
#ports-comms
ports-converters
ports-databases
#ports-deskutils
ports-devel
ports-dns
ports-editors
#ports-emulators
#ports-finance
#ports-french
ports-ftp
#ports-games
#ports-german
#ports-graphics
#ports-hebrew
#ports-hungarian
#ports-irc
#ports-japanese
#ports-java
#ports-korean
ports-lang
ports-mail
ports-math
ports-misc
#ports-multimedia
ports-net
#ports-net-im
#ports-net-mgmt
#ports-net-p2p
#ports-news
#ports-palm
#ports-polish
#ports-ports-mgmt
#ports-portuguese
#ports-print
#ports-russian
#ports-science
ports-security
ports-shells
ports-sysutils
ports-textproc
#ports-ukrainian
#ports-vietnamese
ports-www
#ports-x11
#ports-x11-clocks
#ports-x11-drivers
#ports-x11-fm
#ports-x11-fonts
#ports-x11-servers
#ports-x11-themes
#ports-x11-toolkits
#ports-x11-wm

然后 更新 Ports到最新

# cvsup -L 2 -g /etc/supfile

 

安装 screen(这个是很有必要,除非你在本地)

除非你确信在最长可达半天的编译时间里不会因为任何因素掉线,否则尽可能用屏幕保持软件,如果编译一大半突然断线,那就很麻烦了

# cd /usr/ports/sysutils/screen/
# make install clean

options 里直接点 OK 就可以了。编译安装完成后,打入 screen 进入 screen 环境,会有一个提示信息,直接点击回车就好,然后正常进行编译过程。如果断线,可以在重新连上 SSH 后通过下面的命令回到前面的工作中。

screen -r

 

安装 MySQL

Ports 里提供了很多版本的 MySQL,这里我选择了 5.5

# cd /usr/ports/databases/mysql55-server
# make WITH_CHARSET=gbk WITH_XCHARSET=all BUILD_OPTIMIZED=yes BUILD_STATIC=yes install clean

即可,慢慢等吧,要花一些时间的。

如果提示 Error when bootstrapping CMake: Cannot find appropriate Makefile processor on this system. Please specify one using environment variable MAKE.

安装下cmake即可:

pkg_add cmake -v -r

安装完成后,在 /usr/local/share/mysql/ 里有很多预先设置好的 MySQL 配置文件,可以根据自己的需要选择这些预先设置好的文件,或者根据自己的需要,写配置文件。

# cp /usr/local/share/mysql/my-medium.cnf /usr/local/etc/my.cnf
# rehash
# echo mysql_enable=”YES” >> /etc/rc.conf
# /usr/local/etc/rc.d/mysql-server start

FreeBSD 下安装 MySQL 后,脚本会自动为其建立用户、用户组 mysql。可以根据自己需要,设置安全策略。

安装 PHP 版本 5.3 .*(5.3最新版本)

# cd /usr/ports/lang/php53/
# make config

这里我根据自己需要,选择了(图片截取自5.3.9)

# make install clean

之后安装 PHP5 的扩展库

# cd /usr/ports/lang/php53-extensions
# make config

在对话框中,选择需要的(编译扩展是最耗时间的,至少2-3小时以上,根据需要能少选就少选!以后可以单个安装

[X] BCMATH bc style precision math functions
[X] BZ2 bzip2 library support
[ ] CALENDAR calendar conversion support
[X] CTYPE ctype functions
[X] CURL CURL support
[ ] DBA dba support
[ ] DBASE dBase library support
[X] DOM DOM support
[ ] EXIF EXIF support
[ ] FILEINFO fileinfo support
[X] FILTER input filter support
[ ] FRIBIDI FriBidi support
[ X] FTP FTP support
[X] GD GD library support
[ ] GETTEXT gettext library support
[ ] GMP GNU MP support
[X] HASH HASH Message Digest Framework
[X] ICONV iconv support
[ ] IMAP IMAP support
[ ] INTERBASE Interbase 6 database support (Firebird)
[X] JSON JavaScript Object Serialization support
[ ] LDAP OpenLDAP support
[ ] MBSTRING multibyte string support
[X] MCRYPT Encryption support
[X] MHASH Crypto-hashing support
[ ] MING ming shockwave flash support
[ ] MSSQL MS-SQL database support
[X] MYSQL MySQL database support
[ ] MYSQLI MySQLi database support
[ ] NCURSES ncurses support (CLI only)
[ ] ODBC unixODBC support
[X] OPENSSL OpenSSL support
[ ] PCNTL pcntl support (CLI only)
[X] PCRE Perl Compatible Regular Expression support
[ ] PDF PDFlib support (implies GD)
[X] PDO PHP Data Objects Interface (PDO)
[X] PDO_SQLITE PDO sqlite driver
[X] PDO_MYSQL PDO mysql driver
[ ] PGSQL PostgreSQL database support
[X] POSIX POSIX-like functions
[ ] PSPELL pspell support
[ ] READLINE readline support (CLI only)
[ ] RECODE recode support
[X] SESSION session support
[ ] SHMOP shmop support
[X] SIMPLEXML simplexml support
[ ] SNMP SNMP support
[ X] SOAP SOAP support
[X ] SOCKETS sockets support
[X] SPL Standard PHP Library
[X] SQLITE sqlite support
[ ] SYBASE_CT Sybase database support
[ ] SYSVMSG System V message support
[ ] SYSVSEM System V semaphore support
[ ] SYSVSHM System V shared memory support
[ ] TIDY TIDY support
[X] TOKENIZER tokenizer support
[ ] WDDX WDDX support (implies XML)
[X] XML XML support
[X] XMLREADER XMLReader support
[ ] XMLRPC XMLRPC-EPI support
[X] XMLWRITER XMLWriter support
[ ] XSL XSL support (Implies DOM)
[ ] YAZ YAZ support (ANSI/NISO Z39.50)
[X ] ZIP ZIP support
[X] ZLIB ZLIB support

选择完成后,继续

# make install clean

经过漫长的等待(估计得一个多小时呢),终于完成了编译。启用 PHP-FPM

# echo php_fpm_enable=”YES” >> /etc/rc.conf
# /usr/local/etc/rc.d/php-fpm start

PHP-FPM 的配置文件,在 FreeBSD 下位于 /usr/local/etc/php-fpm.conf,可以自行更改

安装 nginx

nginx 的编译所用的时间相对于前两个东西而言,就快非常多了

# cd /usr/ports/www/nginx
# make install clean

编译选项

[ ] DEBUG Enable nginx debugging
[ ] DEBUGLOG Enable debug log (–with-debug)
[ ] FILE_AIO Enable file aio
[X] IPV6 Enable IPv6
[ ] GOOGLE_PERFTOOLS Enable google perftools module
[X] HTTP_MODULE Enable HTTP module
[ ] HTTP_ADDITION_MODULE Enable http_addition module
[X] HTTP_CACHE_MODULE Enable http_cache module
[ ] HTTP_DAV_MODULE Enable http_webdav module
[ ] HTTP_FLV_MODULE Enable http_flv module
[ ] HTTP_GEOIP_MODULE Enable http_geoip module
[X] HTTP_GZIP_STATIC_MODULE Enable http_gzip_static module
[ ] HTTP_IMAGE_FILTER_MODULE Enable http_image_filter module
[ ] HTTP_PERL_MODULE Enable http_perl module
[ ] HTTP_RANDOM_INDEX_MODULE Enable http_random_index module
[ ] HTTP_REALIP_MODULE Enable http_realip module
[X] HTTP_REWRITE_MODULE Enable http_rewrite module
[ ] HTTP_SECURE_LINK_MODULE Enable http_secure_link module
[X] HTTP_SSL_MODULE Enable http_ssl module
[X] HTTP_STATUS_MODULE Enable http_stub_status module
[ ] HTTP_SUB_MODULE Enable http_sub module
[ ] HTTP_XSLT_MODULE Enable http_xslt module
[ ] MAIL_MODULE Enable IMAP4/POP3/SMTP proxy modul
[ ] MAIL_IMAP_MODULE Enable IMAP4 proxy module
[ ] MAIL_POP3_MODULE Enable POP3 proxy module
[ ] MAIL_SMTP_MODULE Enable SMTP proxy module
[ ] MAIL_SSL_MODULE Enable mail_ssl module
[X] WWW Enable html sample files
[ ] CACHE_PURGE_MODULE 3rd party cache_purge module
[ ] ECHO_MODULE 3rd party echo module
[ ] HEADERS_MORE_MODULE 3rd party headers_more module
[ ] HTTP_ACCEPT_LANGUAGE 3rd party accept_language module
[ ] HTTP_ACCESSKEY_MODULE 3rd party http_accesskey module
[ ] HTTP_AUTH_PAM_MODULE 3rd party http_auth_pam module
[ ] HTTP_AUTH_REQ_MODULE 3rd party http_auth_request module
[ ] HTTP_EVAL_MODULE 3rd party eval module
[ ] HTTP_FANCYINDEX_MODULE 3rd party http_fancyindex module
[ ] HTTP_GUNZIP_FILTER 3rd party http_gunzip_filter modul
[ ] HTTP_MOGILEFS_MODULE 3rd party mogilefs module
[ ] HTTP_MP4_H264_MODULE 3rd party mp4/h264 module
[ ] HTTP_NOTICE_MODULE 3rd party notice module
[ ] HTTP_PUSH_MODULE 3rd party push module
[ ] HTTP_REDIS_MODULE 3rd party http_redis module
[ ] HTTP_RESPONSE_MODULE 3rd party http_response module
[ ] HTTP_UPLOAD_MODULE 3rd party upload module
[ ] HTTP_UPLOAD_PROGRESS 3rd party uploadprogress module
[ ] HTTP_UPSTREAM_FAIR 3rd party upstream fair module
[ ] HTTP_UPSTREAM_HASH 3rd party upstream hash module
[ ] HTTP_UPSTREAM_KEEPALIVE 3rd party upstream keepalive modul
[ ] HTTP_ZIP_MODULE 3rd party http_zip module
[ ] MEMC_MODULE 3rd party memc (memcached) module
[ ] PASSENGER_MODULE 3rd party passenger module
[ ] SLOWFS_CACHE_MODULE 3rd party slowfs_cache module
[ ] SUPERVISORD_MODULE 3rd party supervisord module
[ ] SYSLOG_SUPPORT 3rd party syslog support
[ ] UDPLOG_MODULE 3rd party udplog (syslog) module

编译完成后,启动 nginx

# echo nginx_enable=”YES” >> /etc/rc.conf

这里先不急着 start nginx,因为现在还没有对 PHP 的支持。

# vi /usr/local/etc/nginx/nginx.conf

将如下段落前的 “#” 删除,并且将 html 更改为 /usr/local/www/nginx

location ~ \.php$ {
root /usr/local/www/nginx;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

结束后,编辑 /usr/local/etc/nginx/fastcgi_params,加入

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

启动 nginx,看看是否已经对 PHP 了

# /usr/local/etc/rc.d/nginx start
# echo “<?php phpinfo() ?>” > /usr/local/www/nginx/info.php

访问 http://yourdomain/info.php,看到 phpinfo 的页面则证明无误。

安装 eAcceletrator

eAcceletrator 可以预编译你的 PHP,这样执行的时候,就会起到加速作用。(下图红色地址部分需要根据自己编译结束后给出的地址修改

# cd /usr/ports/www/eaccelerator
# make install clean
# echo zend_extension=”/usr/local/lib/php/20060613/eaccelerator.so” >> /usr/local/etc/php.ini
# mkdir /tmp/eaccelerator
# chown www /tmp/eaccelerator
# chmod 0700 /tmp/eaccelerator
# /usr/local/etc/rc.d/php-fpm restart

再刷新刚才的 info.php,看看是不是加入了 eAcceletrator 的支持

安装memcached

cd /usr/ports/databases/memcached
make install clean

cd /usr/ports/databases/pecl-memcache
make install clean
echo “memcached_enable=YES” >> /etc/rc.conf

开启 /usr/local/etc/rc.d/memcached start

 

下面附上安装过程中会下载的软件(只供大致参考,一般都需要自己下载,可以配置163的镜像源)

/usr/ports/distfiles/xcb-proto-1.6.tar.bz2
/usr/ports/distfiles/varnish-3.0.2.tar.gz
/usr/ports/distfiles/unzip60.tar.gz
/usr/ports/distfiles/tcl8.5.11-src.tar.gz
/usr/ports/distfiles/t1lib-5.1.2.tar.gz
/usr/ports/distfiles/suhosin-patch-5.3.9-0.9.10.patch.gz
/usr/ports/distfiles/sqlite-src-3071000.zip
/usr/ports/distfiles/screen-4.0.3.tar.gz
/usr/ports/distfiles/repcached-2.3.1-1.4.10.patch.gz
/usr/ports/distfiles/redis-2.4.4.tar.gz
/usr/ports/distfiles/php-5.3.9.tar.bz2
/usr/ports/distfiles/pcre-8.21.tar.bz2
/usr/ports/distfiles/pcre-8.20.tar.bz2
/usr/ports/distfiles/openldap-2.4.26.tgz
/usr/ports/distfiles/nss-3.13.1.with.ckbi.1.88.tar.gz
/usr/ports/distfiles/nload-0.7.3.tar.gz
/usr/ports/distfiles/Nginx_upstream_hash-0.3.1.tar.gz
/usr/ports/distfiles/nginx_upstream_fair-20090923.tar.gz
/usr/ports/distfiles/nginx-1.0.11.tar.gz
/usr/ports/distfiles/mysql-5.5.20.tar.gz
/usr/ports/distfiles/memcached-1.4.10.tar.gz
/usr/ports/distfiles/make-3.82.tar.bz2
/usr/ports/distfiles/m4-1.4.16.tar.bz2
/usr/ports/distfiles/libxcb-1.7.tar.bz2
/usr/ports/distfiles/libtool-2.4.tar.gz
/usr/ports/distfiles/libpthread-stubs-0.3.tar.bz2
/usr/ports/distfiles/libpng-1.4.8.tar.xz
/usr/ports/distfiles/libpng-1.4.8-apng.patch.gz
/usr/ports/distfiles/libmcrypt-2.5.8.tar.gz
/usr/ports/distfiles/libiconv-1.13.1.tar.gz
/usr/ports/distfiles/libgpg-error-1.10.tar.bz2
/usr/ports/distfiles/libgcrypt-1.5.0.tar.bz2
/usr/ports/distfiles/libexecinfo-1.1.tar.bz2
/usr/ports/distfiles/libevent-1.4.14b-stable.tar.gz
/usr/ports/distfiles/IO-Tty-1.10.tar.gz
/usr/ports/distfiles/help2man-1.40.5.tar.gz
/usr/ports/distfiles/haproxy-1.4.16.tar.gz
/usr/ports/distfiles/gettext-1.05.tar.gz
/usr/ports/distfiles/gettext-0.18.1.1.tar.gz
/usr/ports/distfiles/freetype-2.4.7.tar.bz2
/usr/ports/distfiles/eaccelerator-0.9.6.1.tar.bz2
/usr/ports/distfiles/cyrus-sasl-2.1.25.tar.gz
/usr/ports/distfiles/curl-7.21.3.tar.bz2
/usr/ports/distfiles/cmake-2.8.7.tar.gz
/usr/ports/distfiles/check-0.9.8.tar.gz
/usr/ports/distfiles/automake-1.11.1.tar.bz2
/usr/ports/distfiles/autoconf-2.68.tar.bz2
/usr/ports/distfiles/agentzh-headers-more-nginx-module-v0.16-0-gde77fd2.tar.gz
/usr/ports/distfiles/xorg
/usr/ports/distfiles/ruby
/usr/ports/distfiles/python
/usr/ports/distfiles/PECL
/usr/ports/distfiles/jpeg8b2
/usr/ports/distfiles/gnome2

博文原址:http://www.ppkj.net/?p=986

discuzx2 反向代理后url出现被代理端口号解决

星期六, 一月 14th, 2012

前端如果代理的话,discuzx2会自动检测端口并加上,去掉也很简单

注释掉 /source/class/class_core.php 180行即可

// $_G[‘siteport’] = empty($_SERVER[‘SERVER_PORT’]) || $_SERVER[‘SERVER_PORT’] == ’80’ ? ” : ‘:’.$_SERVER[‘SERVER_PORT’];

varnish与discuzx部署问题

星期六, 一月 14th, 2012

varnish做最前端,nginx做反向代理,配置完毕之后可能会遇到无法登陆discuzx后台的情况,

此时将discuzx配置文件config/config_global.php里面的

$_config[‘admincp’][‘checkip’] 设置为0即可

Linux下shell快速查找PHP木马(转)

星期四, 十二月 1st, 2011

Linux shell快速查找PHP木马(本博客未验证可用性)

一句话查找PHP木马

# find ./ -name "*.php" |xargs egrep "phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decoolcode|spider_bc"> /tmp/php.txt
# grep -r --include=*.php '[^a-z]eval($_POST' . > /tmp/eval.txt
# grep -r --include=*.php 'file_put_contents(.*$_POST\[.*\]);' . > /tmp/file_put_contents.txt
# find ./ -name "*.php" -type f -print0 | xargs -0 egrep "(phpspy|c99sh|milw0rm|eval\(gzuncompress\(base64_decoolcode|eval\(base64_decoolcode|spider_bc|gzinflate)" | awk -F: '{print $1}' | sort | uniq

查找最近一天被修改的PHP文件

# find -mtime -1 -type f -name  *.php

修改网站的权限

# find -type f -name \*.php -exec chmod 444 {} \;
# find ./ -type d -exec chmod 555{} \;

PHP版本的选择(转)

星期三, 十一月 30th, 2011

从PHP5.2.6版本开始,有None-Thread Safe与Thread Safe两种版本的可供选择,这两种版本有何不同?

先从字面意思上理解,None-Thread Safe就是非线程安全,在执行时不进行线程(thread)安全检查;Thread Safe就是线程安全,执行时会进行线程(thread)安全检查,以防止有新要求就启动新线程的 CGI 执行方式耗尽系统资源。

再来看PHP的两种执行方式:ISAPI和FastCGI。

FastCGI执行方式是以单一线程来执行操作,所以不需要进行线程的安全检查,除去线程安全检查的防护反而可以提高执行效率,所以,如果是以 FastCGI(无论搭配 IIS 6 或 IIS 7)执行 PHP ,都建议下载、执行 non-thread safe 的 PHP (PHP 的二进位档有两种包装方式:msi 、zip ,请下载 zip 套件)。

而线程安全检查正是为ISAPI方式的PHP准备的,因为有许多php模块都不是线程安全的,所以需要使用Thread Safe的PHP。

所以,对于PHP5.2选择Thread Safe版本安装,而对于PHP5.3则下载None-Thread Safe,执行PHP比较有效率。

另外,PHP还有VC6,VC9版本之分。

VC6 版本是使用 Visual Studio 6 编译器编译的,如果你的 PHP 是用 Apache 来架设的,那你就选择 VC6 版本。

VC9 版本是使用 Visual Studio 2008 编译器编译的,如果你的 PHP 是用 IIS 来架设的,那你就选择 VC9 版本。

php preg_replace 匹配左右为空格的星号

星期五, 九月 23rd, 2011

要封装一个php分页,想只输入一条sql就能同时完成获取查询总数和返回查询的数据,于是把sql写成带*的(返回所有列),但是外联查询的时候也可能会带*,不能简单替换,于是用正则匹配左右为空的*号然后替换,也可以输入个特定值比如 select 1 form,把1当做匹配对象

<?php
$word="select * from left f left join right r on f.id=r.id where f.*=1";
echo preg_replace('/\s\*\s/'," count(*) ",$word)
?>

结果

select count(*) from left f left join right r on f.id=r.id where f.*=1;

试用yaf框架(php c扩展开发的高性能框架)

星期六, 九月 17th, 2011

一直在使用几个轻量级的框架,原因就是速度问题,即便装上了加速器,在稍大点的项目里面仍然很慢,google搜索了下,发现竟然有个国人开发的yaf框架,下载安装在了windows上面初步测试hello world 开启视图,性能很不错,下面是第一次访问和第二次访问的基准测试时间,安装了eAccelerator加速器,所以第一次耗时较第二次长一点(时间取的都是多次刷新稳定后最接近的值)

第二次

性能很可观,不过目前功能还不是很完善,比较其他框架还有一段路要走,好在版本更新很快

之后也在centos 5.6 x64编译安装了yaf,暂时还没测试,不过1.0总体感觉不错 bootstrap也有,按照作者说法,这个框架是zendframework的C实现,感觉很有前景,其实smarty如果也是c扩展开发,就更加强大了

pecl里面的yaf最新测试版http://pecl.php.net/package/Yaf

下载后需要先安装php-devel和 pcre-devel (没这个编译会出错)

Centos执行 yum install php-devel pcre-devel
Debian ubuntu执行 sudo apt-get install libpcre3 libpcre3-dev
Freebsd下:
cd /usr/ports/www/pecl-yaf
make instal clean
下载解压后
cd yaf-2.1.2
phpize
./configure --with-php-config=/usr/bin/php-config
make
make install

需要注意的是:控制器(如controllers/Index.php)文件第一个字母为大写,否则linux下面是无法运行的

小注:pcre是什么

Perl兼容正则表达式库,是一套和perl5有着相同语法语义的的正则表达式模式匹配实现

The PCRE library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5. PCRE has its own native API, as well as a set of wrapper functions that correspond to the POSIX regular expression API. The PCRE library is free, even for building proprietary software.

php 连接sqlserver2005,2008,2008R2 解决办法

星期四, 六月 9th, 2011

第一种方法使用php默认自带的php-mssql.dll扩展,这种只需要开启php.ini,去除“;”即可

;extension=php-mssql.dll

这种方式需要ntwdblib.dll放在c:\windows以及php安装根目录

如果无法安装,查看以下原因:

1.扩展是否已经加载,用 phpinfo()查看 php-mssql;

2.本机是否已经安装sqlserver2000-2008R2

3.有时候ntwdblib.dll(比如2000.2.8)的版本并不支持更高版本的sql server(大于2000),因此如果你的ntwdblib.dll版本过低,可以下载本站下载ntwdblib.dll,下载后在php安装目录和c:\windows下各自放一份

4.查看是否当前账户名和主机名一样了,改成不一样的,我的电脑/计算机 右键属性 —重命名计算机

5.开启sqlserver的远程连接

———————————–下面是开启sqlserver远程 2008R2下通过 其他可能会有所不同——————————————-

接下来要设置sqlserver允许远程连接,打开SQL Server Management Studio ,登陆后 ,在左侧 对象资源管理器里面,选择sqlserver实例对象(第一个),右键属性

1.安全性选项卡 里面勾选sqlserver和windows身份验证

2.连接选项卡 勾选允许远程连接

然后打开SQL Server 配置管理器

1.–>SQL Server网络配置里面,SQLEXPRESS协议(可能是其他名),右侧NamedPipes和TCP/IP都开启,编辑TCP/IP,选项卡里面–>ip地址->IPALL –>tcp动态端口 写入1433

2.SQL Native Client配置–>客户端协议同样启用上面的两个协议即可。

然后在SQL Server Management Studio重启sqlserver即可,注意如果不是本地连接需要开启防火墙sqlserver链接 一般端口是1433

 

————————————-下面的不推荐用—–ppkj.net————————————

另一种方法微软自己提供了php连接mssql的dll扩展, 但是函数接口都和php自带扩展不一样,需要重新学习

微软官方下载地址

以下在windows7 SQLServer2008 R2 x64环境 php5.2.16ts apache2.2下通过

先查看php的编译信息

<?php phpinfo();?>

查找 Thread Safety  如果是enabled 则使用对应版本号的ts版本,其他的则使用nts版本

安装后重启web服务器

如果phpinfo里面有sqlsrv扩展,则成功

 

 

下载的文件里面有sqlsrv的接口说明,一些函数如下

Function Description
sqlsrv_begin_transaction Begins a transaction.
sqlsrv_cancel Cancels a statement; discards any pending results for the statement.
sqlsrv_client_info Provides information about the client.
sqlsrv_close Closes a connection. Frees all resources associated with the connection.
sqlsrv_commit Commits a transaction.
sqlsrv_configure Changes error handling and logging configurations.
sqlsrv_connect Creates and opens a connection.
sqlsrv_errors Returns error and/or warning information about the last operation.
sqlsrv_execute Executes a prepared statement.
sqlsrv_fetch Makes the next row of data available for reading.
sqlsrv_fetch_array Retrieves the next row of data as a numerically indexed array, an associative array, or both.
sqlsrv_fetch_object Retrieves the next row of data as an object.
sqlsrv_field_metadata Returns field metadata.
sqlsrv_free_stmt Closes a statement. Frees all resources associated with the statement.
sqlsrv_get_config Returns the value of the specified configuration setting.
sqlsrv_get_field Retrieves a field in the current row by index. The PHP return type can be specified.
sqlsrv_has_rows Detects if a result set has one or more rows.
sqlsrv_next_result Makes the next result available for processing.
sqlsrv_num_rows Reports the number of rows in a result set.
sqlsrv_num_fields Retrieves the number of fields in an active result set.
sqlsrv_prepare Prepares a Transact-SQL query without executing it. Implicitly binds parameters.
sqlsrv_query Prepares and executes a Transact-SQL query.
sqlsrv_rollback Rolls back a transaction.
sqlsrv_rows_affected Returns the number of modified rows.
sqlsrv_send_stream_data Sends up to eight kilobytes (8 KB) of data to the server with each call to the function.
sqlsrv_server_info Provides information about the server.

iis6配置phpfast-cgi

星期二, 五月 17th, 2011

1.下载php windows installer 安装时选择iis fast-cgi

2.配置php.ini最下面添加

cgi.force_redirect = 0

cgi.fix_pathinfo = 1

fastcgi.impersonate=1

session.save_path = c:/temp

3.C:\WINDOWS\system32\inetsrv\fcgiext.ini

添加如下内容 其中路径需要修改为你的安装路径

[Types]php=php5

[php5]ExePath=D:\server\PHP5\php-cgi.exe

EnvironmentVars=PHPRC:D:\server\PHP5\php.ini,PHP_FCGI_MAX_REQUESTS:10000

4.在IIS里面 右键网站选择属性->主目录->配置->应用程序扩展,添加

可执行文件为 C:\WINDOWS\system32\inetsrv\fcgiext.dll

扩展名为php

动作 选择 全部

勾选脚本引擎以及确认文件是否存在

5.web服务扩展里面,新添加一个可执行文件

地址为php-cig解释器 C:\WINDOWS\system32\inetsrv\fcgiext.dll,设置为允许执行

重启网站

如果有  Server API    CGI/FastCGI,则已经配置成功

另可以参考此网页

http://www.laozhuzhu.com/a/detail/Using-FastCGI-to-Host-PHP-Applications-on-IIS6.aspx