PHP Warning: preg_match_all(): Compilation failed: unrecognized character after (?< at offset



reference link:

http://www.aviank.com/techtalk/php-warning-preg_match_all-compilation-failed-unrecognized-character-after-at-offset/

While using preg_match_all function in php, i came across this issue of Compilation Failed.

On executing

preg_match_all(‘/

(?.*)<\/li>/sU’, $body, $matches)
I got the following error:

PHP Warning: preg_match_all(): Compilation failed: unrecognized character after (?< at offset 32 in … This is probably you are having old version of pcre (for me it was 6.6-6) which needs to be updated to 8.0 or higher. Default CentOS Repositories dont have the latest version, for this you can use Utter Ramblings yum repository Steps to Add the Utter Ramblings yum repository Create a file /etc/yum.repos.d/utterramblings.repo and paste the following:-

[utterramblings]
name=Jason’s Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

#then run

sudo yum –enablerepo=utterramblings install pcre
Thats it, just in case you get some error messages as:-

Transaction Check Error:

file /usr/share/man/man1/pcretest.1.gz from install of pcre-8.02-1.jason.1.x86_64 conflicts with file from package pcre-6.6-6.el5_6.1.i386

then it might be because your system is 64 bit and you need to remove i386 version of lib, to fix it run

sudo yum remove pcre-6.6-6.el5_6.1.i386
sudo yum –enablerepo=utterramblings install pcre


Installing Python2.6.7 On CentOS5

Source Link: http://www.hostucan.com/webmaster-tutorials/centos-python-2.6-install
Install Python 2.6 on CentOS 5

CentOS 5 is the most common Python hosting environment in the market, but the default version of python it is 2.4 now. As some projects request the python version to be greater than V2.5, in this article, you will see how to install python 2.6 by compiling source code step by step.

1. Download python source from python.org and Uncompress it.

$ wget http://www.python.org/ftp/python/2.6.7/Python-2.6.7.tgz
$ tar xzvf Python-2.6.7.tgz
2. Build & Install. In the source code folder:
$ ./configure –prefix=/opt/python2.6 –with-threads –enable-shared –with-zlib=/usr/include
$ make
$ make install
3. Add Python 2.6 lib to system lib. execute:
$ sudo ln -s /opt/python2.6/lib/libpython2.6.so /usr/lib
$ sudo ln -s /opt/python2.6/lib/libpython2.6.so.1.0 /usr/lib

# Create necessary links and cache
$ sudo /sbin/ldconfig -v

# make a symbolic link to python
$ sudo ln -s /opt/python2.6/bin/python /usr/local/python
4. Check python version use “python -V”. If you still see old version of Python, you need to edit /etc/profile (as root), add the following line:
pathmunge /opt/python2.6/bin/
Above setting should be added before the line like:
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
Then re-login system, try “python -V” again. 5. After install yum, try “yum search php” This is to make sure we did not accidentally mess up “yum”, which is the biggest threat when upgrading Python version. If you see no errors, you should be good to start using Python 2.6.

Update python-MySQLdb

http://blog.csdn.net/inte_sleeper/article/details/6556103

在 CentOS 5.5 上安装 Git

Refernece link: http://blog.sonitech.org/2010/12/04/%E5%9C%A8-centos-5-5-%E4%B8%8A%E5%AE%89%E8%A3%85-git/

在 Ubuntu 上安装 Git 非常的简单,只需要:

sudo apt-get install git-core
但是 CentOS 默认的 yum 源中没有 Git,只能下载 RPM 包安装,确保已安装了依赖的包

sudo yum install curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel
安装最新的 Git

$ wget http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz
$ tar xzvf git-latest.tar.gz
$ cd git-{date}
$ autoconf
$ ./configure
$ make
$ sudo make install
检查版本

$ git –version
git version 1.7.3.GIT

chattr to change the file or dir’s attribute

Command:

chattr

Usage: chattr +=-
+ :在原有参数设定基础上,追加参数。
– :在原有参数设定基础上,移除参数。
= :更新为指定参数设定。
A:文件或目录的 atime (access time)不可被修改(modified), 可以有效预防例如手提电脑磁盘I/O错误的发生。
S:硬盘I/O同步选项,功能类似sync。
a:即append,设定该参数后,只能向文件中添加数据,而不能删除,多用于服务器日志文 件安全,只有root才能设定这个属性。
c:即compresse,设定文件是否经压缩后再存储。读取时需要经过自动解压操作。
d:即no dump,设定文件不能成为dump程序的备份目标。
i:设定文件不能被删除、改名、设定链接关系,同时不能写入或新增内容。i参数对于文件 系统的安全设置有很大帮助。
j:即journal,设定此参数使得当通过mount参数:data=ordered 或者 data=writeback 挂 载的文件系统,文件在写入时会先被记录(在journal中)。如果filesystem被设定参数为 data=journal,则该参数自动失效。
s:保密性地删除文件或目录,即硬盘空间被全部收回。
u:与s相反,当设定为u时,数据内容其实还存在磁盘中,可以用于undeletion.

各参数选项中常用到的是a和i。a选项强制只可添加不可删除,多用于日志系统的安全设定。而i是更为严格的安全设定,只有superuser (root) 或具有CAP_LINUX_IMMUTABLE处理能力(标识)的进程能够施加该选项。
应用实例:
1、用chattr命令防止系统中某个关键文件被修改
# chattr +i /etc/fstab
然后试一下rm mv rename等命令操作于该文件,都是得到Operation not permitted 的结果
2、让某个文件只能往里面追加内容,不能删除,一些日志文件适用于这种操作
# chattr +a /data1/user_act.log
知识点[2]:为何要设置5分钟后自动登出
由于客户的维护人员常常登陆上去后通过直接关闭TERM端口非法退出telnet,造成系统的pts进程越来越多,一个月下来竟然近百,当进程过多的时候系统就会产生报警。规范操作应该是用exit或者ctrl+D,但是其他人并不这样操作,所以我们定义了echo “TMOUT=300” >>/etc/profile这一项内容,是让服务器自动剔除300秒没有任何动作的客户端。当然了这一项大家可以根据实际需求而决定是否添加

self-testing:

touch 123
chattr +i 123
rm 123
rm: remove write-protected regular empty file `123′? y
rm: cannot remove `123′: Operation not permitted
chattr -i 123
rm 123 && echo OK
OK

Nginx ssl 测试工具及报告

缘起:

近几日,公司接入facebook 的游戏,要求所有的数据走SSL通道,找到测试工具 ab, curl-loader

 

1.  ab

ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.

ab -n request_number -c concurrent number

ab -t 120 -n 10000000 -c 250 URL

Request data: 18K

Result:

过程:在测试初期,ab 没有加 -k (keep-alive 参数),结果每次请求,都是短连接,也就是说每次请求都需求对证书进行加密解密,CPU一下子暴到了 90%以上,期间换过3台Server 都是RPS均在 2000-4000 之间徘徊。

将测试参数改为长连接测试后,系统CPU 有明显的提升,但是还是在6000RPS左右。未能达到要求。

将较高安全级别的加密从Nginx 的SSL 解密过程中剔除后,CPU 的的Load就降了下来主要参数就是有 ssl_ciphers HIGH:!aNULL:!MD5:!kEDH;

调试之后的结果,非常满意:

90% time  per request 50 以下,并发2000 时,RPS 达到了 4万+ 以下是具体的测试数据:

Duration(s) Number of Client concurrent numbers per client Succeed request/second Complete request Number of Failed request CPU Core cpuMHZ notes
300s 8 250 43215/sec 12965039 119 16 44.30%
300s 8 500 45640/sec 13693073 1148 16 45.00%
300s 8 250 43202/sec 12960970 144 16 Openssl 1.0.0e nginx 1.1.0

 

2. curl-loader

ab的工具固然很好,但是有一个缺陷,就是每次请求,没有sleep time interval, 这样并不能很好的保证数据的准确性,所以,又找了另一个测试工具,curl-loader. 这个工具十分强大,我只用了小小的一部分功能。

基本安装:

URL: http://superb-sea2.dl.sourceforge.net/project/curl-loader/curl-loader/curl-loader-0.53/curl-loader-0.53.tar.bz2

wget http://superb-sea2.dl.sourceforge.net/project/curl-loader/curl-loader/curl-loader-0.53/curl-loader-0.53.tar.bz2 -P /usr/local/src/
cd /usr/local/src;
tar jxf  curl-loader-0.53.tar.bz2 &&
 cd curl-loader-0.53.tar.bz2 &&
 make

这时需求一个标准库 redhat下名为:c-ares ,用yum 安装就OK

yum install c-ares
echo 'export LD_LIBRARY_PATH=/usr/local/src/curl-loader-0.53/lib' >>/root/.bashrc

 

用法: curl-loader -f your.conf

在编译目录下,有一个名为 conf-examples 的配置样本的集合,合https.conf为例:进行相应的修改:如下:

 

########### GENERAL SECTION ################################
BATCH_NAME= https  #

CLIENTS_NUM_MAX=500# Same as CLIENTS_NUM 最大Client数

CLIENTS_NUM_START=100 # 起始Client数

CLIENTS_RAMPUP_INC=50 # 递增Client数

INTERFACE   =eth0 #请求网卡

NETMASK=16  #你懂的。

IP_ADDR_MIN= 10.20.99.213# 模拟起始IP,这次我只用了一台机器,所以开始和最后是一个 🙂

IP_ADDR_MAX= 10.20.99.213 #

CYCLES_NUM=200 # 这个比较重要,就是循环请求次数,比如我们最大请求Client为500,这个为200总请求就是10万. PS:值为 -1 时,为无限循环。

URLS_NUM= 1 #如果你有多个URL进行测试,这个真写个数,不过我只测试了一个


########### URL SECTION ####################################
URL=https://10.20.100.23/index.html

#URL=https://localhost/apache2-default/ACE-INSTALL.html

#URL=https://localhost/ACE-INSTALL.html

URL_SHORT_NAME="url-https"

REQUEST_TYPE=GETTIMER_URL_COMPLETION = 0 # In msec. When positive, Now it is enforced by cancelling url fetch on timeout

TIMER_AFTER_URL_SLEEP =500

 

以下是我的测试结果:

Request data size: 43K
Sleep time Internal: 1 second
RPS: 8000 requests/s
Time per requests: 87 ms
Client numbers: 4000 (实际nginx active connection numbers 为3300左右)

 

 

附:Nginx SSL部分的配置(红色部分很重要,去除EDH加密。)

Nginx 参数设置:

worker_processes  8;

events {    use epoll;    worker_connections  10240;}

server {
listen 443;
server_name SUBDOMAIN.happyelements.com
ssl on;
ssl_certificate all.happyelements.com.cert;
ssl_certificate_key all.happyelements.com.uns.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5:!kEDH; 
proxy_set_header X-Forwarded-Proto https;

access_log logs/ssl.w5-fish-ssl.happyelements.com.log
}

location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
#auth_basic_user_file conf/htpasswd;
}
}

location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
#auth_basic_user_file conf/htpasswd;
}

 

How to become a hacker —

There are basically five kinds of things you can do to be respected by hackers:

1. The first (the most central and most traditional) is to write programs that other hackers think are fun or useful, and give the program sources to the whole hacker culture to use.

Hackerdom’s most revered demigods are people who have written large, capable programs that met a widespread need and given them away, so that now everyone uses them.

2. Help test and debug free software

They also serve who stand and debug free software. In this imperfect world, we will inevitably spend most of our software development time in the debugging phase. That’s why any free-software author who’s thinking will tell you that good beta-testers (who know how to describe symptoms clearly, localize problems well, can tolerate bugs in a quickie release, and are willing to apply a few simple diagnostic routines) are worth their weight in rubies. Even one of these can make the difference between a debugging phase that’s a protracted, exhausting nightmare and one that’s merely a salutory nuisance.
If you’re a newbie, try to find a program under development that you’re interested in and be a good beta-tester. There’s a natural progression from helping test programs to helping debug them to helping modify them. You’ll learn a lot this way, and generate good karma with people who will help you later on.

3. Publish useful information.

Another good thing is to collect and filter useful and interesting information into Web pages or documents like FAQs (Frequently Asked Questions lists), and make those generally available.
Maintainers of major technical FAQs get almost as much respect as free-software authors.

4. Help keep the infrastructure working.

The hacker culture (and the engineering development of the Internet, for that matter) is run by volunteers. There’s a lot of necessary but unglamorous work that needs done to keep it going — administering mailing lists, moderating newsgroups, maintaining large software archive sites, developing RFCs and other technical standards.
People who do this sort of thing well get a lot of respect, because everybody knows these jobs are huge time sinks and not much fun as playing with code. Doing them shows dedication.

5. Serve the hacker culture itself.

Finally, you can serve and propagate the culture itself (by, for example, writing an accurate primer on how to become a hacker :-)). This is not something you’ll be positioned to do until you’ve been around for while and become well-known for one of the first four things.
The hacker culture doesn’t have leaders, exactly, but it does have culture heroes and tribal historians and spokespeople. When you’ve been in the trenches long enough, you may grow into one of these. Beware: hackers distrust blatant ego in their tribal elders, so visibly reaching for this kind of fame is dangerous. Rather than striving for it, you have to sort of position yourself so it drops in your lap, and then be modest and gracious about your status.

Points For Style

Again, to be a hacker, you have to enter the hacker mindset. There are some things you can do when you’re not a computer that seem to help. They’re not substitutes for hacking(nothing is) but many hackers do them, and feel that they connect in some basic way with the essence of hacking.

  • Read science fiction. Go to science fiction conventions (a good way to meet hackers and proto-hackers).
  • Study Zen, and/or take up martial arts. (The mental discipline seems similar in important ways.)
  • Develop an analytical ear for music. Learn to appreciate peculiar kinds of music. Learn to play some musical instrument well, or how to sing.
  • Develop your appreciation of puns and wordplay.
  • Learn to write your native language well. (A surprising number of hackers, including all the best ones I know of, are able writers.)

The more of these things you already do, the more likely it is that you are natural hacker material. Why these things in particular is not completely clear, but they’re connected with a mix of left- and right-brain skills that seems to be important (hackers need to be able to both reason logically and step outside the apparent logic of a problem at a moment’s notice).