易截截图软件、单文件、免安装、纯绿色、仅160KB

php多线程上下文中安全写文件

提供一个php多线程上下文中安全写文件的实现方法。这个实现没有使用php 的file lock机制,使用的是临时文件机制。多线程中的各个线程都是对各自(每个线程独占一个)的临时文件写,然后再同步到原文件中。
<?php
/**
* @usage: used to offer safe file write operation in multiple threads context, arbitory file type
* @author: Rocky Zhang
* @time: Nov. 11 2009
* @demo[0]: $handler = mfopen($file, 'a+');
*        mfwrite($handler, $str);
*/
function mfopen($file, $mode='w+') {
    $tempfile = generateTempfile('./tempdir', $file);
    preg_match('/b/i', $mode) || ($mode .= 'b'); // 'b' is recommended
    if (preg_match('/\w|a/i', $mode) && !is_writable($file)) {
        exit("{$file} is not writable!");
    }
    $filemtime = $filemtime2 = 0;
    $tempdir = dirname($tempfile);
    is_dir($tempdir) || mkdir($tempdir, 0777);
    do { // do-while used to avoid modify in a long time copy
        clearstatcache();
        $filemtime = filemtime($file);
        copy($file, $tempfile);
        $filemtime2 = filemtime($file);
    } while ( ($filemtime2 - $filemtime) != 0 );
    if (!$handler = fopen($tempfile, $mode)) {
        exit('Fail on opening tempfile, write authentication is must on temporary dir!');
    }
    return array(0=>$handler, 1=>$filemtime, 2=>$file, 3=>$tempfile, 4=>$mode);
}
// I do think that this function should be optimized further
function mfwrite(&$handler, $str='') {
    if (strlen($str) > 0) {
        $num = fwrite($handler[0], $str);
      


相关文档:

php中的字符串连接

// 定义一个新变量
$test = "hello";
//  .  字符串连接符
echo $test.".world"     // hello.world
 echo "$test.world"     // "" 中的变量将被解析成相应的值
             &nbs ......

php 发送 Email


< ?php   
require("mail/class.phpmailer.php");//调用   
$mail = new PHPMailer();//实例化phpmailer   
$address = "mailxi@126.com";//接收邮件的邮箱   
$mail->IsSMTP(); // 设置发送邮件的协议:SMTP   
......

PHP会话(Session)使用入门


  对比起 Cookie,Session 是存储在服务器端的会话,相对安全,并且不像 Cookie 那样有存储长度限制,本文简单介绍 Session 的使用。
  由于 Session 是以文本文件形式存储在服务器端的,所以不怕客户端修改 Session 内容。实际上在服务器端的 Session 文件,PHP 自动修改 Session 文件的权限,只保留了系统读和写权 ......

ubuntu9.04中安装配置php5 + MySql + Apache

   - -!   真不容易啊,弄了一天,终于搞定了!
  在ubuntu9.04下安装,首先要准备的东西很多,大部分是用来支持php的库,废话不多说,写这个也是为了便于我以后查看用,记忆不行,咳。。有需要的朋友也可以来去用。
  在ubuntu上安装,有一个好处就是有新立得这个软件,首先先安装mysql, ......

什么是PHP类和类的对象(PHP的类简介)

 
类(Class):是一些变量与一些使用这些变量的函数的集合。
可简单理解为函数和变量的集合,或变量和函数的定义的集合。
语法是:
class Class_name //习惯上类的第一个字符为大写,并且必须符合变量的命名规则。
{
//函数与变量的集合(一些变量(类成员)和函数(行为方法)的定义)。
}
数据成员(变量)在� ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号