使用新主题了,大家给个意见哈

[转载]php加速 PHP APC 浅析

十二 29th, 2011

php加速 PHP APC 浅析

 

原文链接:http://www.perfgeeks.com/?p=298

PHP APC提供两种缓存功能,即缓存Opcode(目标文件),我们称之为apc_compiler_cache。同时它还提供一些接口用于PHP开发人员将用户数据驻留在内存中,我们称之为apc_user_cache。我们这里主要控讨php-apc的配置。

安装PHP APC

作为测试环境,我们这里使用的是CentOS5.3(2.6.18-128.el5PAE) + Apache2.0(prefork) + php5.2。我们可以去pecl apc下载APC-3.0.19.tgz

# tar -xzvf APC-3.0.19.tgz
#cd  APC-3.0.19
# /usr/bin/phpize
# ./configure --enable-apc --enable-mmap --enable-apc-spinlocks --disable-apc-pthreadmutex
#make
#make install

注意:我们这里支持mmap,同时采用spinlocks自旋锁。Spinlocks是Facebook推荐使用,同时也是APC开发者推荐使用的锁机制。

PHP APC 配置参数

如果你使用的系统环境跟我的测试环境是一样的话,可以在/etc/php.d目录下创建文件apc.ini,并且相关配置写入/etc/php.d/apc.ini文件。这里,我们挑了一些常用到的配置,并进行探讨。把相关的配置放在一起解释。

apc.enabled=1
apc.enabled默认值是1,你可设成0禁用APC。如果你设置为0的时候,同样把extension=apc.so也注释掉(这样可以节约内存资源)。一旦启用了APC功能,则会缓存Opcodes到共享内存。

apc.shm_segments = 1
apc.shm_size = 30
APC既然把数据缓存在内存里面,我们就有必要对它进行内存资源限定。通过这二个配置可以限定APC可以使用的内存空间大小。 apc.shm_segments指定了使用共享内存块数,而apc.shm_size则指定了一块共享内存空间大小,单位是M。所以,允许APC使用的 内存大小应该是 apc.shm_segments * apc.shm_size = 30M。你可以调整一块共享内存的大小空间。当然,一块共享内存最大值是受操作系统限制的,即不能超过/proc/sys/kernel/shmmax大 小。否则APC创建共享内存的时候,会失败。在apc.shm_size达到了上限的时候,你可以通过设置apc.shm_segments来允许APC 使用更多的内存空间。我们推荐,如果调用APC使用内存空间的话,先考滤apc.shm_size,后考滤apc.shm_segments。具体数值, 可以根据apc.php监控情况进行规划与调整。值得注意的是,每一次调整需要重启httpd守护进程,这样可以重新加载apc.so模块。跟随着 httpd守护进程启动,apc.so模块就会加载。apc.so加载初始化的时候,通过mmap请求分配内存指定大小的内存,即 apc.shm_size * apc.shm_segments。而且,这里使用的是匿名内存映射方式,通过映射一个特殊设备/dev/zero,提供一个“大型”的,填满了零的内存 供APC管理。
为了验证以上陈述,我们注释掉apc.ini配置,并且写了以下php脚本观察apc.so模块初始化的分配的内存空间。

<?php
//@file: apc_load.php
if (!extension_loaded('apc')) {
  dl('apc.so');		#加载apc.so模块
  echo posix_getpid();	#//输出当前进程的pid,我这里这里输出的是14735
  ob_flush();
  flush();
  sleep(3600);		#让进程进入休眠状态.这样,我们可以观察内存分配情况
 }
?>
#strace -p `cat /var/run/httpd.pid`
open("/var/www/html/apc_load.php", O_RDONLY) = 13
...
mmap2(NULL, 31457280, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0) = 0xb5ce7000
...
nanosleep({3600, 0},

红色部分,我们可以看出。通过mmap系统内核调用分配了30M(31457280/1024/1024)内存空间。 PROT_READ|PROT_WRITE表示该内存空间可供读取与写入。MAP_SHARED表示该内存空间与其它进程是共享的,即其它进程也可以进行 读取与写入,我们可以通过apc.php进行管理该块内存空间亦是受益于此设定。MAP_ANONYMOUS则表示匿名映射。其中fd=-1表示忽略,因 为这里映射的特殊设备/dev/zero。最后的0表示无偏移量。我们还可以通过进程映像文件查看该块内存的具体情况
#cat /proc/14735/smaps

b5ce7000-b7ae7000 rw-s 00000000 00:08 633695     /dev/zero (deleted)
Size:		30720 kB
Rss:		44 kB
Shared_Clean:	0 kB
Shared_Dirty: 	0 kB
Private_Clean: 	0 kB
Private_Dirty: 	44 kB

可以很容易地发现起始地址0xb5ce7000与上面mmap系统内核调用返回的地址一样。该块内存是可读写rw,并与其它进程共享s。而/dev /zero则是映射文件,该文件节点是633695。其中,size表示进程可以使用的内存空间,而rss则表示实际分配的内存空间,且由 Private_Dirty可以看出,实际分配的44kb内存是由当前进程自己分配的。

apc.num_files_hint = 1000
apc.user_entries_hint = 4096
这二配置指定apc可以有多少个缓存条目。apc.num_files_hint说明你估计可能会有多少个文件相应的opcodes需要被缓成,即大约可 以有多少个apc_compiler_cache条目。另外apc.user_entries_hint则说明你估计可能会有多少个 apc_userdata_cache条目需要被缓存。如果项目中不使用apc_store()缓存用户数据的话,该值可以设定得更小。也就是说 apc.num_files_hint与apc.user_entries_hint之和决定了APC允许最大缓存对象条目的数量。准确地设置这二个值可 以得到最佳查询性能。当然,如果你不清楚要进行多少缓存(缓存对象实例)的情况下,你可以不必修改这二项配置。
其中apc.user_entries_hint要根据项目实际开发使用了apc_store()条目估计其值大小。相较而 言,apc.num_files_hint可以通过find命令,更容易地估计其大小。比如我们的web根目是/var/vhosts,则使用下面的 find命令可以大致地统计当前apc.num_files_hint数目.
#find /var/vhosts \( -name “*.php” -or -name “*.inc” \) -type f -print |wc -l
1442

apc.stat = 1
apc.stat_ctime = 0
这二个参数,只跟apc_compiler_cache缓存相关,并不影响apc_user_cache。我们前面提到过 apc_complier_cache,它缓存的对象是php源文件一一对应的opcodes(目标文件)。PHP源文件存放在磁盘设备上,与之相对应的 Opcodes目标文件位置内存空间(共享内存),那么当php源文件被修改以后,怎么通知更新内存空间的opcodes呢?每次接收到请求后,APC都 会去检查打开的php源文件的最后修改时间,如果文件的最后修改时间与相应的内存空间缓存对象记录的最后修改时间不一致的话,APC则会认为存放在内存空 间的Opcode目标文件(缓存对象)已经过期了,acp会将缓存对象清除并且保存新解析得到的Opcode。我们关心的是,即便没有更新任何php源文 件,每次接受到http请求后,APC都会请求系统内核调用stat()来获取php源文件最后修改时。我们可以通过将apc.stat设置为0,要求 APC不去检查Opcodes相对应的php源文件是否更新了。这样可以获得最佳的性能,我们也推荐这么做。不过,这样做有一点不好的就是,一旦有PHP 源文件更新了之后,需要重启httpd守护进程或者调用apc_cache_clear()函数清空APC缓存来保证php源文件与缓存在内存空间的 Opcodes相一致。

<?php
define('ROOTP', dirname(__FILE__) . '/');
include(ROOTP . 'i1.php');
require(ROOTP . 'i2.php');
include_once(ROOTP . 'i3.php');
require_once(ROOTP . 'i4.php');
require(ROOTP . 'i5.php');
include(ROOTP . 'i6.php');
?>
# strace -e trace=file -p `cat /var/run/httpd.pid`
getcwd("/var/www/html", 4096)           = 14
stat64("/var/www/html/i1.php", {st_mode=S_IFREG|0644, st_size=39, ...}) = 0
stat64("/var/www/html/i2.php", {st_mode=S_IFREG|0644, st_size=39, ...}) = 0
lstat64("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/var/www", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/var/www/html", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/var/www/html/i3.php", {st_mode=S_IFREG|0644, st_size=39, ...}) = 0
open("/var/www/html/i3.php", O_RDONLY)  = 12
stat64("/var/www/html/i3.php", {st_mode=S_IFREG|0644, st_size=39, ...}) = 0
lstat64("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/var/www", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/var/www/html", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/var/www/html/i4.php", {st_mode=S_IFREG|0644, st_size=39, ...}) = 0
open("/var/www/html/i4.php", O_RDONLY)  = 12
stat64("/var/www/html/i4.php", {st_mode=S_IFREG|0644, st_size=39, ...}) = 0
stat64("/var/www/html/i5.php", {st_mode=S_IFREG|0644, st_size=39, ...}) = 0
stat64("/var/www/html/i6.php", {st_mode=S_IFREG|0644, st_size=39, ...}) = 0
chdir("/tmp")                           = 0

# strace -e trace=file -p `cat /var/run/httpd.pid`
getcwd("/var/www/html", 4096)           = 14
open("/var/www/html/i3.php", O_RDONLY)  = 12
open("/var/www/html/i4.php", O_RDONLY)  = 12
chdir("/tmp")                           = 0

对比可见,当apc.stat=0时,省了很多系统内核调用,我们没有看到系统内核调用stat64了。其中,i3.php和i4.php分别是 php的include_once和require_once函数调用,它要交给fstat()系统内核调用来检查文件是否打开过。单从性能角度出发的 话,require比require_once性能更佳。

设置apc.stat_ctime的意义并是很大。如果apc.stat_ctime值为1时,仅当php源文件的创建时间(ctime)大于 php源文件的最后修改时间(mtime)时,缓存对象的mtime时间会被php源文件的ctime所代替,否则缓存对象的mtime依然记录为php 源文件的mtime。这样做是防止通过cvs, svn或者rsync等工具刷新php源文件的mtime,这样会导致APC通过比对php源文件的创建时间ctime来决定缓存对象有没有过期。我们推 荐该保持默认值,即apc.stat_ctime = 0

apc.ttl=0
apc.user_ttl=0
缓存对象的生命周期。其中ttl表示Time To Live,意味着指定时间后缓存对象会被清除。其中0表示永不过期。我们前面提过,APC能缓存的条目是受限定的,如果你把ttl设置永不过期的话,当缓存条目已满或者缓存空间不够,之后的缓存都将失败。
其中apc.ttl作用于apc_compiler_cache。当apc.ttl大于0时,每次请求都会对比这次的请求时间与上一次请求时间之差是不是大于apc.ttl,如果大于apc.ttl,则会被认缓存条目过期了,会被清理。
比较有意思的是apc.user_ttl,它主要作用于apc_user_cache缓存。我们知道,这种类型的缓存是通过 apc_store($key, $var, $ttl = 0)创建的缓存对象。函数apc_store()中指定的$ttl与php.ini中设定的apc.user_ttl有什么异同,是我们比较关心的。因为 它们同样作用于apc_userdata_cache缓存。经过分析,我们知道:判断apc_user_cache缓存过期的依据是,当 apc.user_ttl大于0,且这次http请求时间与上一次http请求时间之差大于apc.user_ttl,则认为相应的缓存条目已过期;或 者,user.data.ttl(php函数apc_store()中指定的$ttl)大于0,且这次http请求时间与缓存对象创建时间ctime之差 大于user.data.ttl,则同样认为缓存条目已过期,会被清除。
我们推荐,如果你的项目较为稳定,并且apc.stat设置为0。同时apc.shm_size、apc.num_files_hint设置合理的 话,apc.ttl建议设置为0。即apc_compiler_cache永不回收,直到重启httpd守护进程或者调用函数 apc_cache_clear()清缓存。至于apc.user_ttl,建议设置为0,由开发人员调用apc_store()函数的时候,设 置$ttl来指定该缓存对象的生命周期。

apc.slam_defense=0
apc.write_lock=1
apc.file_update_protection=2
之所以把这三个配置放在一起解释,是因为他们的意义很相近。其中apc.file_update_protection最好理解,它的单位是时间单位秒。 如果当前http请求时间与php源文件最好修改时间mtime之差小于apc.file_update_protection时间,APC则不会缓存该 php源文件与之对应的Opcodes,直到接下来的某次访问,并且访问时间与php源文件的最后修改时间大于 apc.file_update_protection时间,相之相应的Opcodes才会被缓存到共享内存空间。这样做的好处是,不容易被用户访问到你 正在修改的源文件。我们推荐在开发环境,该值可以设置得更大一点,但在运营环境,我们推荐保留默认值即可。
当你的网站并发量很大的时候,可能出现由http守护进程fork的多个子进程同时缓存同一份Opcodes的情况。通过 apc.slam_defense则可以减少这种事情的发生机率。比如,apc.slam_defense值设置为60的时候,当遇到未缓存的 Opcodes,每100次有60次是不缓存的。对于并发量不大的网站,我们推荐该值设定为0,对于并发量高的网站我们可以根据统计适当地调整该值。而 apc.write_lock是一个布尔值,当该值设置为1的时候,当多个进程同时缓存同一份Opcodes时,仅当最先那个进程缓存有效,其它的无效。 通过apc.write_lock设置,有效地避免了缓存写竞争的出现。

apc.max_file_size=1M
apc.filters = NULL
apc.cache_by_default=1
这三个配置放在一起,是因为他们都用于限制缓存。其中apc.max_file_size表示如果php源文件超过了1M,则与之对应的opcodes不 被缓存。而apc.filters指定一个文件过滤列表,以逗号(,)隔开。当apc.cache_by_default等于1时,与 apc.filters列表中指定的文件名相匹配的文件不会被缓存。相反,apc.cache_by_default等于0时,仅缓存与 acp.filters列表中指定的文件相匹配的文件。

总结

1,使用Spinlocks锁机制,能够达到最佳性能。
2,APC提供了apc.php,用于监控与管理APC缓存。不要忘记修改管理员名和密码
3,APC默认通过mmap匿名映射创建共享内存,缓存对象都存放在这块”大型”的内存空间。由APC自行管理该共享内存
4,我们需要通过统计调整apc.shm_size、apc.num_files_hints、apc.user_entries_hint的值。直到最佳
5,好吧,我承认apc.stat = 0 可以获得更佳的性能。要我做什么都可以接受.
6,PHP预定义常量,可以使用apc_define_constants()函数。不过据APC开发者介绍说pecl hidef性能更佳,抛异define吧,它是低效的。
7,函数apc_store(),对于系统设置等PHP变量,生命周期是整个应用(从httpd守护进程直到httpd守护进程关闭),使用APC比Memcached会更好。必竟不要经过网络传输协议tcp。
8,APC不适于通过函数apc_store()缓存频繁变更的用户数据,会出现一些奇异现象。

标签:

php日历方法的使用

十一 25th, 2011

我们采用的的西元(公元)历法叫格里高利历(Gregorian calendar),在处理公元前历年时,可以转换为Julian Day表示 ;儒略日(Julian day)是指由公元前4713年1月1日,协调世界时中午12时开始所经过的天数,多为天文学家采用,用以作为天文学的单一历法

这样就保存为Julian Day天数了,方便查询排序。。

<?php
$jd = GregorianToJD(10, 11, -4110); //公元前4110年10月11日
echo "$jd\n";
$jd = GregorianToJD(10, 11, 2011); //公元2011年10月11日
echo "$jd\n";
标签:

ssh超时断开的解决方案

十一 22nd, 2011

当用SSH Secure Shell连接Linux时,如果几分钟没有任何操作,连接就会断开,必须重新登陆才行,每次都重复相同的操作,很是烦人,本文总结了两种解决的方法。

首选方法:配置客户端

1 linux下的ssh命令

vim /etc/ssh/ssh_config

然后找到里面的ServerAliveInterval 参数,如果没有你同样自己加一个就好了。参数意义相同,都是秒数,比如9分钟:

ServerAliveInterval 540

2 SecureCRT

设置反空闲

3 Putty

启用putty keepalive

putty -> Connection -> Seconds between keepalives ( 0 to turn off ),默认为0,改为60。

 

服务端方法:更改ssh服务器的配置文件/etc/ssh/sshd_config

ClientAliveInterval指定了服务器端 向客户端请求消息的时间间隔, 默认是0,不发送。而ClientAliveInterval 60表示每分钟发送一次,然后客户端响应,这样就保持长连接了。这里比较怪的地方是:不是客户端主动发起保持连接的请求(如FTerm, CTerm等),而是需要服务器先主动。

另外,至于ClientAliveCountMax,使用默认值3即可。ClientAliveCountMax表示服务器发出请求后客户端没有响应的次数达到一定值,就自动断开,正常情况下,客户端不会不响应。

ClientAliveCountMax

Sets the number of client alive messages (see below) which may be sent without sshd(8) receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the ses-sion. It is important to note that the use of client alive messages is very different from TCPKeepAlive (below). The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The client alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive.The default value is 3. If ClientAliveInterval (see below) is set to 15, and ClientAliveCountMax is left at the default, unresponsive SSH clients will be disconnected after approximately 45 seconds. This option applies to protocol version 2 only.

ClientAliveInterval

Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client. This option applies to protocol version 2 only.

vim /etc/ssh/sshd_config

找到ClientAliveInterval 参数,如果没有就自己加一行。

ClientAliveInterval 参数的数值是秒,比如你设置为540,就是9分钟.

ClientAliveInterval 540

对于ClientAliveCountMax

指如果发现客户端没有相应,则判断一次超时,这个参数设置允许超时的次数,比如10。

ClientAliveInterval 540

ClientAliveCountMax 10;

则代表允许超时 5400秒 = 90分钟。

 

标签:

VirtualBox: Failed to open a session for the virtual machine

十一 15th, 2011

尝试

sudo /etc/init.d/vboxdrv setup

问题解决

标签:

安装vsftpd,使用pam_mysql管理ftp帐号

九 22nd, 2011

一、安装

sudo apt-get install vsftpd libpam-mysql

vsftpd支持三类用户登录,分别是系统用户、匿名帐户、虚拟帐户; 这里使用虚拟用户方式,并将其用mysql管理

vsftpd认证是使用pam,因此libpam-mysql是必需的

为pam创建数据库: 如pam_users,为此数据增加mysql访问权限,如用户名vsftpd …

为vsftpd创建用户表,如vsftpd,字段分别为user、password

同时也可以增加pam验证的日志表,如logs,字段分别是msg、user、pid、host、rhost、time

二、配置

编辑vsftpd的pam配置文件

sudo vi /etc/pam.d/vsftpd

内容如:

auth    required        pam_mysql.so user=pam passwd=V5WYsWzfEEEGuqm7 host=localhost db=pam_users table=vsftpd usercolumn=user passwdcolumn=password crypt=3 sqllog=1 logtable=logs logmsgcolumn=msg logusercolumn=user logpidcolumn=pid loghostcolumn=host logrhostcolumn=rhost logtimecolumn=time
account required        pam_mysql.so user=pam passwd=V5WYsWzfEEEGuqm7 host=localhost db=pam_users table=vsftpd usercolumn=user passwdcolumn=password crypt=3 sqllog=1 logtable=logs logmsgcolumn=msg logusercolumn=user logpidcolumn=pid loghostcolumn=host logrhostcolumn=rhost logtimecolumn=time

以上为用户验证的表、及日志表连接、字段等信息,其中crypt=3表示密码使用md5加密,0为原文,1为unix加密,2为mysql的password函数加密

修改/etc/vsftpd.conf

添加

guest_enable=YES
guest_username=daemon

user_config_dir=/etc/vsftpd_user_config
user_sub_token=$USER

意义在于:

将虚拟帐户访问方式设为允许、虚拟帐户映射到daemon这个实际用户

将目录/etc/vsftpd_user_config配置为FTP登录帐户的个性化配置目录,文件名为对应的用户名

 

如:我新增test用户的访问配置文件/etc/vsftpd_user_config/test,内容如下

local_root=/var/www
write_enable=YES
anon_world_readable_only=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
anon_umask=022

 

这样,为数据表pam_users.vsftpd增加一条test用户的记录,就能FTP登录了

标签:

mysql5.5.12 在ubuntu下编译安装

五 28th, 2011

今天发现MySQL源码包变了,需要使用cmake编译安装了
作个记录,备忘。。
1. 安装需要的工具

sudo apt-get install libncurses5-dev cmake

2.添加mysql组及用户

groupadd mysql
useradd -r -g mysql mysql

3.安装

sudo tar zxf mysql-5.5.12.tar.gz
cd mysql-5.5.12
sudo cmake .
sudo make
sudo make install
 
cd /usr/local/mysql
sudo chown mysql.mysql -R .
sudo scripts/mysql_install_db --user=mysql

4.可选额外设置

sudo cp support-files/my-medium.cnf /etc/my.cnf
sudo cp support-files/mysql.server /etc/init.d/mysqld
service mysqld start
#设置root密码
/usr/local/mysql/bin/mysqladmin -u root password '123456'
#把mysql客户端工具拷到系统目录
sudo cp /usr/local/mysql/bin/mysql /usr/bin

 


官方参考地址: http://dev.mysql.com/doc/refman/5.5/en/installing-source-distribution.html

标签:

安装使用MySQL-Python

五 20th, 2011

1).从: http://sourceforge.net/projects/mysql-python 下载MySQLdb库:最新得到的是MySQL-python-1.2.3.tar.gz
#mysql-python需要setuptools,如果没有先安装它
#http://pypi.python.org/pypi/setuptools#cygwin-mac-os-x-linux-other 根据自己的python版本下载相应的setuptools-0.6c8-py2.4.egg
#sh setuptools-0.6c11-py2.4.egg

2)安装

tar zxf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
python setup.py build
python setup.py install

3) 如果以apache cgi运行python脚本,那我们稍微修改下http.conf,添加如下

#python cgi
SetEnv PYTHON_EGG_CACHE /tmp
AddHandler cgi-script .cgi
&lt;Directory "/var/www/html/python/cgi"&gt;
 Options Indexes FollowSymLinks Execcgi
 AllowOverride All
 Order allow,deny
 Allow from all
&lt;/Directory&gt;

PYTHON_EGG_CACHE需要一个可以的目录用来存放MySQL_Python的cache
.cgi后缀作为cgi脚本运行: AddHandler cgi-script .cgi
为目录”/var/www/html/python/cgi” 添加Execcgi选项,并确保该目录可执行

4)测试脚本

#!/usr/bin/python
import cgitb
cgitb.enable(display=0, logdir="./tmp/")
print "Content-type: text/html\r\n"
import _mysql
db=_mysql.connect("localhost","root","passwd","test")
db.query("SELECT * FROM documents WHERE id=1")
r=db.store_result()
print r.fetch_row();
标签:

使用VboxManage实现宿主机到虚拟机的端口转发

一 20th, 2011

VBoxManage modifyvm “VM name” –natpf1 “guestssh,tcp,,2222,,22″

With the above example, all TCP traffic arriving on port 2222 on any host interface will be forwarded to port 22 in the guest. The protocol name tcp is a mandatory attribute defining which protocol should be used for forwarding (udp could also be used).

VM name : 为虚拟机名

natpf1 : The number after --natpf denotes the network card, like in other parts of VBoxManage.

guestssh: The name guestssh is purely descriptive and will be auto-generated if omitted.

To remove this forwarding rule again, use the following command:

VBoxManage modifyvm "VM name" --natpf1 delete "guestssh"

If for some reason the guest uses a static assigned IP address not leased from the built-in DHCP server, it is required to specify the guest IP when registering the forwarding rule:

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,10.0.2.19,22"

详见: http://www.virtualbox.org/manual/ch06.html#natforward

标签:

才注意到php不支持无符号整型-_-!

十 8th, 2010

今天无意看手册,发现php对integer型有这样一段描述:

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that’s 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18. PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.

明确说了PHP does not support unsigned integers.
测试了一下是这样~32位机下最大整数是2147483647(2的31次-1)最小是-2147483648(负2的31次)首位永远是符号位了,如果越界就是float了

标签:

setsebool

九 20th, 2010

设置一个selinux的布尔值。

 一些常见项:

===ftp===
//If you want to share files anonymously
chcon -R -t public_content_t /var/ftp
//If you want to setup a directory where you can upload files
chcon -t public_content_rw_t /var/ftp/incoming
You must also turn on the boolean allow_ftpd_anon_write
setsebool -P allow_ftpd_anon_write=1
//If you are setting up this machine as a ftpd server and wish to allow users to access their home directorories
setsebool -P ftp_home_dir 1
//If you want to run ftpd as a daemon
setsebool -P ftpd_is_daemon 1
//You can disable SELinux protection for the ftpd daemon
setsebool -P ftpd_disable_trans 1

===httpd===
//If you want a particular domain to write to the public_content_rw_t domain
setsebool -P allow_httpd_anon_write=1
or
setsebool -P allow_httpd_sys_script_anon_write=1
//httpd can be setup to allow cgi scripts to be executed
setsebool -P httpd_enable_cgi 1
//If you want to allow access to users home directories
setsebool -P httpd_enable_homedirs 1
chcon -R -t httpd_sys_content_t ~user/public_html
//httpd is allowed access to the controling terminal
setsebool -P httpd_tty_comm 1
//such that one httpd service can not interfere with another
setsebool -P httpd_unified 0
//loadable modules run under the same context as httpd
setsebool -P httpd_builtin_scripting 0
//httpd scripts are allowed to connect out to the network
setsebool -P httpd_can_network_connect 1
// You can disable suexec transition
setsebool -P httpd_suexec_disable_trans 1
//You can disable SELinux protection for the httpd daemon by executing
setsebool -P httpd_disable_trans 1
service httpd restart

===named===
//If you want to have named update the master zone files
setsebool -P named_write_master_zones 1
//You can disable SELinux protection for the named daemon by executing
setsebool -P named_disable_trans 1
service named restart

===nfs===
//If you want to setup this machine to share nfs partitions read only
setsebool -P nfs_export_all_ro 1
//If you want to share files read/write
setsebool -P nfs_export_all_rw 1
//If you want to use a remote NFS server for the home directories on this machine
setsebool -P use_nfs_home_dirs 1

===samba===
//If you want to share files other than home directorie
chcon -t samba_share_t /directory
//If you want to share files with multiple domains
setsebool -P allow_smbd_anon_write=1
//If you are setting up this machine as a Samba server and wish to share the home directories
setsebool -P samba_enable_home_dirs 1
//If you want to use a remote Samba server for the home directories on this machine
setsebool -P use_samba_home_dirs 1
//You can disable SELinux protection for the samba daemon by executing
setsebool -P smbd_disable_trans 1
service smb restart

===rsync===
//If you want to share files using the rsync daemon
chcon -t public_content_t /directories
//If you want to share files with multiple domains
setsebool -P allow_rsync_anon_write=1
//You can disable SELinux protection for the rsync daemon by executing
setsebool -P rsync_disable_trans 1

===kerberos===
//allow your system to work properly in a Kerberos environment
setsebool -P allow_kerberos 1
//If you are running Kerberos daemons kadmind or krb5kdc
setsebool -P krb5kdc_disable_trans 1
service krb5kdc restart
setsebool -P kadmind_disable_trans 1
service kadmind restart

===nis===
Allow your system to work properly in a NIS environment
setsebool -P allow_ypbind 1

标签: