The implementation method of PHP optimization and high efficiency speed-increasing problem 1th/2 page _php tips

Source: Internet
Author: User
Tags explode mysql query setcookie
in a function, it is more efficient to use return than to use global when passing an array, for example:


function Userloginfo ($usertemp) {


$detail =explode ("|", $usertemp);


return $detail;


}


$login =userloginfo ($USERDB);


than


function Userloginfo ($usertemp) {


Global $detail;


$detail =explode ("|", $usertemp);


}


Userloginfo ($USERDB);


to be efficient


II, (this code is used to get the program directory corresponding URL, recommended)
$urlarray =explode ('/', $HTTP _server_vars[' Request_uri ');


$urlcount =count ($urlarray); unset ($urlarray [$urlcount-1]);


$ofstarurl = ' http://'. $HTTP _server_vars[' http_host '].implode ('/', $urlarray);


This code is more than


$pre _urlarray=explode ('/', $HTTP _server_vars[' http_referer ');


$pre _url=array_pop ($pre _urlarray);


to be efficient


third, in the cycle of judgment, the value of the use of identity is equal to the efficient


$a =2; $b = 2;


like
.

if ($a = = $b) $c = $a;


than


if ($a = = = $b) $c = $a;


Efficient


Four, MySQL query when possible to use where in less limit
limit check many records of the first few, fast, but the most of the query will be slow


use in. On query continuity records, very fast, discontinuous records first run will be slightly slower, but later will be faster!


Five, NT Server data operation stability is less than unix/linux


Six, use the Ob_start () as far as possible before the output;


can speed up output, apply NT or Nuli/linux, use Ob_start (' Ob_gzhandler ') for Unlix class servers, and output efficiency will be higher


Seven, try to use if ($a = = his value) when judging


Use if (empty ($a)) as much as possible, because the program runs faster


viii.!= and <> efficiency are quite
when use is unequal

Nine, personal experience to use $a = "11111111111111"; The efficiency and $a = ' 11111111111111 '; Quite. Not as much as the book says.


10, the use of standardized SQL statements, will be conducive to the analysis of MySQL


11, using


if ($online) {


$online 1= $online;


Setcookie (' Online1 ', $online, $cookietime, $ckpath, $ckdomain, $secure);


}


cookies will take effect immediately


Use


if ($online)


Setcookie (' online1 ', $online, $cookietime, $ckpath, $ckdomain, $secure);


cookies need to be refreshed again to take effect


12, using


$handle =fopen ($filename, WB);


Flock ($handle, lock_sh);


$filedata =fread ($handle, FileSize ($filename));


fclose ($handle);


than


file ($filename);


must be excellent in speed and stability


Current 1/2 page 12 Next read the full text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.