函数mkdir有两个参数,目录路径和访问权限
例mkdir('/tmp/test',0777)
然后要得到的权限码,不一定是上边设定的,当前系统的umask将会与设定的值‘与’,这样子才是真正的权限码,例如,如果umask为022,那码上边得到的权权限码为0755,没有写的权限
所以如果我们想要真正的得到0777的权限,代码
$oldumask=umask(0);
mkdir('test',0777);
umask($oldumask);
?>
umask()检查并修改当前的umask码,并返回当前的umask码
umask 是什么?
我们创建文件的默认权限是怎么来的?如何改变这个默认权限呢?
1.使用 ip2long() 和 long2ip() 函数来把 IP 地址转化成整型存储到数据库里。这种方法把存储空间降到了接近四分之一(char(15) 的 15 个字节对整形的 4 个字节),计算一个特定的地址是不是在一个区段内页更简单了,而且加快了搜索和排序的速度(虽然有时仅仅是快了一点)。
2.在验证 email 地址的时候使用 checkdnsrr() 函数验证域名是否存在。这个内置函数能够确认指定的域名能够解析成 IP 地址。该函数的PHP 文档的用户评论部分有一个简单的用户自定义函数,这个函数基于 checkdnsrr(),用来验证 email 地址的合法性。对于那些认为自己的 email 地址是 “joeuser@wwwphp.net” 而不是 “joeuser@php.net” 的家伙们,这个方法可以很方便的抓住他们。
3.如果你使用的是 PHP 5 和 MySQL 4.1 或者更高的版本,考虑抛弃 mysql_* 系列函数改用改进版的 mysqli_* 系列函数。一个很好的功能就是你可以使用预处理语句,如果你在维护一个数据库密集型站点,这个功能能够加快查询速度。一些评估分数。
使用方法:// mysql connect
$db = new SQL('mysql:host=localhost;database=21andy_blog;', '21andy.com_user', '21andy.com_password');
// PDO SQLite3 connect
$db = new SQL('pdo:database=/21andy.com/21andy.sqlite3;');
// SQLite2 connect
$db = new SQL('sqlite:database=/21andy.com/21andy.sqlite;');
If you upgraded to PHP 5.3, chances are high you’re going to run into a few warnings or deprecated function messages.
An example is the ereg family of functions, which are gone for good, as they were slower and felt less familiar than the alternative Perl-compatible preg family.
To migrate ereg():
ereg('\.([^\.]*$)', $this->file_src_name, $extension);
becomes
preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension);
Notice that I wrapped the pattern (\.([^\.]*$)) around / /, which are RegExp delimiters. If you find yourself escaping / too much (for an URL for example), you might want to use the # delimiter instead.
英文版权归Reinhold Weber所有,中译文作者yangyang(aka davidkoree)。双语版可用于非商业传播,但须注明英文版作者、版权信息,以及中译文作者。翻译水平有限,请广大PHPer指正。
1. If a method can be static, declare it static. Speed improvement is by a factor of 4. 如果一个方法可静态化,就对它做静态声明。速率可提升至4倍。
2. echois faster thanprint.echo比print快。
3. Use echo’s multiple parameters instead of string concatenation. 使用echo的多重参数(译注:指用逗号而不是句点)代替字符串连接。
4. Set the maxvalue for your for-loops before and not in the loop. 在执行for循环之前确定最大循环数,不要每循环一次都计算最大值。
5. Unset your variables to free memory, especially large arrays. 注销那些不用的变量尤其是大数组,以便释放内存。