Tag Archives: php

use unix socket instead of tcp connection for memcached to speed up web servers

By default, memcached is listening on port 11211 for all connections. But for a single server, it’s better to config memcached to use unix socket which improve the performance and reduce the legacy.

On freebsd, it’s easy to change from TCP/IP to unix socket. But there are some steps you need to pay more attention.

1. Modify rc.conf to force memcached to use unix socket.

2. Modify the connection string in your php files.
For TCP connection, use

If you are using php-memcache, you should change it to

If you are using php-memcached, you should change it to

3. Another thing I found in Freebsd is that if you force memcached to use unix socket, every time you restart the service, memcached will change the socket file permission to 550 which means php can’t connect to the socket file. So you need to grant php user access to that file.

You need to do this each time after you restart memcached.

FreeBSD10.1: separate static access and script (php) access for nginx

This article is based on the php fourm Discuz (http://www.discuz.net), you should modify the configuration as needed.

Operation system: Freebsd 10.1 with ZFS

1. Enable httpready, aio, tmpfs

2. Create tmp mount point for nginx

3. Nginx configuration (nginx version 1.6)

compile nginx from port

make sure that you have enabled below modules:

create log folder

below is the configuration for nginx. Please be aware that I put the configuration in several different files.

main:

events:

http:

I will use map.conf and front.conf to separate static access and script access, also separate human access and robot access.

Use map.conf to sort out different access type:

map.conf:

Use LUA to identify the robots which pretend to be a web browser

cookie.conf (for this script, please refer to http://ocdn.me/nginx-defense.html)

Front.conf

upstream.conf

site/yourdomain.conf

logorotate

With this configuration, you can set different access rules for human access and bot access, you can also seperate static file access and script(php) access. It can spped up your website and improve the workload of your server.

修改php支持的内存大小

测试xaraya的时候,安装过程中说运行需要的php使用内存至少为8m。只能修改了。。
 
nano /etc/php5/apache2/php.ini
找到
 
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
 
max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 8M      ; Maximum amount of memory a script may consume (8MB)

修改成需要的大小就可以了