Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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×Ö·û´®º¯Êý´óÈ«

AddSlashes: ×Ö·û´®¼ÓÈëбÏß¡£
bin2hex: ¶þ½øÎ»×ª³ÉÊ®Áù½øÎ»¡£
Chop: È¥³ýÁ¬Ðø¿Õ°×¡£
Chr: ·µ»ØÐòÊýÖµµÄ×Ö·û¡£
chunk_split: ½«×Ö·û´®·Ö³ÉС¶Î¡£
convert_cyr_string: ת»»¹Å˹À­·ò×Ö·û´®³ÉÆäËü×Ö·û´®¡£
crypt: ½«×Ö·û´®Óà DES ±àÂë¼ÓÃÜ¡£
echo: Êä³ö×Ö·û´®¡£
explode: Çпª×Ö·û´®¡£
flush: Çå³öÊä³ö»º³åÇø¡£
get ......

¶¨Òåphp³£Á¿

³£Á¿¿ÉÒÔÀí½âΪֵ²»±äµÄ±äÁ¿¡£³£Á¿Öµ±»¶¨Òåºó£¬Ôڽű¾µÄÆäËûÈκεط½¶¼²»Äܱ»¸Ä±ä¡£Ò»¸ö³£Á¿ÓÉÓ¢ÎÄ×Öĸ¡¢Ï»®Ïß¡¢ºÍÊý×Ö×é³É£¬µ«  Êý×Ö²»ÄÜ×÷ΪÊ××Öĸ³öÏÖ¡£
ÔÚphpÖÐʹÓÃdefaine()º¯ÊýÀ´¶¨Òå³£Á¿£¬¸Ãº¯ÊýµÄÓï·¨¸ñʽΪ£º
define(string constant_name, mixed value, case_sensitive = true)
¸Ãº¯ÊýÓÐ3¸ö²ÎÊý£º
cons ......

phpÖÐheader()º¯ÊýʹÓÃ˵Ã÷

eader()º¯ÊýʹÓÃ˵Ã÷£º  
 
Ò»¡¢×÷Ó㺠 
~~~~~~~~~  
       PHPÖ»ÊÇÒÔHTTPЭÒ齫HTMLÎĵµµÄ±êÍ·Ë͵½ä¯ÀÀÆ÷£¬¸æËßä¯ÀÀÆ÷¾ßÌåÔõô´¦ÀíÕâ¸öÒ³Ãæ£¬ÖÁÓÚ´«Ë͵ÄÄÚÈÝÔòÐèÒªÊìϤһÏÂHTTPЭÒéÁË£¬ÓëPHPÎÞ¹ØÁË£¬¿É²ÎÕÕhttp://www.w3.org/Protocols/rfc2616/rfc2616¡£  
  & ......

phpÖÐheaderº¯ÊýµÄʹÓÃ

header("HTTP/1.0 400 Bad Request");¡¡·µ»Ø400´íÎó
header("HTTP/1.0 404 Not Found"); ·µ»Ø404´íÎó
header("Location:http://$host$uri/$extra"); Ìø×ª
//ÉèÖÃnocache¡¡£¬¹ýÆÚ
header
(
"Cache-Control: no-cache,
must-revalidate"
);
//
HTTP/1.1
header
(
&q ......

ʲôÊÇPHPÀàºÍÀàµÄ¶ÔÏó(PHPµÄÀà¼ò½é)

 
ÀࣨClass£©£ºÊÇһЩ±äÁ¿ÓëһЩʹÓÃÕâЩ±äÁ¿µÄº¯ÊýµÄ¼¯ºÏ¡£
¿É¼òµ¥Àí½âΪº¯ÊýºÍ±äÁ¿µÄ¼¯ºÏ£¬»ò±äÁ¿ºÍº¯ÊýµÄ¶¨ÒåµÄ¼¯ºÏ¡£
Óï·¨ÊÇ£º
class Class_name //ϰ¹ßÉÏÀàµÄµÚÒ»¸ö×Ö·ûΪ´óд£¬²¢ÇÒ±ØÐë·ûºÏ±äÁ¿µÄÃüÃû¹æÔò¡£
{
//º¯ÊýÓë±äÁ¿µÄ¼¯ºÏ(һЩ±äÁ¿(Àà³ÉÔ±)ºÍº¯Êý(ÐÐΪ·½·¨)µÄ¶¨Òå)¡£
}
Êý¾Ý³ÉÔ±(±äÁ¿)ÔÚÀ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ