Improve the speed of mobile phone operation the implementation of PHP optimization and efficient speed-up problem 1th/2 page

Source: Internet
Author: User
Tags setcookie
One, in a function, it is more efficient to pass an array using return than to use global, such as:
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
Second, (this code 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 piece of code is more
$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 to determine the ratio is equal to efficient
$a =2; $b = 2;
Like what
if ($a = = $b) $c = $a;
Than
if ($a = = = $b) $c = $a;
Efficient
When MySQL queries, try to use where in less limit
Limit check many records of the first few, fast, but the query the most face will be slow
With in. On query continuity records, very fast, non-continuity records run slightly slower for the first time, but then faster!
V, NT Server data operation stability is less than unix/linux
Vi. use Ob_start () as far as possible before output;
Can speed up output, applicable NT or Nuli/linux, if use Ob_start (' Ob_gzhandler ') for Unlix Class Server, output efficiency will be higher
When judging, try to use if ($a = = his value)
Try to use if (empty ($a)) when negative, because it runs faster
Viii. the use of unequal! = is equivalent to <> efficiency
Ix. the use of personal experience $a = "11111111111111"; The efficiency and $a = ' 11111111111111 '; Not quite as much as the book says.
Ten, the use of standard SQL statements, will facilitate the analysis of MySQL
Xi. Use of
if ($online) {
$
Setcookie (' Online1 ', $online, $cookietime, $ckpath, $ckdomain, $secure);
}
The cookie will take effect immediately.
Use
if ($online)
Setcookie (' Online1 ', $online, $cookietime, $ckpath, $ckdomain, $secure);
The cookie needs to be refreshed again to take effect
12. Use
$handle =fopen ($filename, WB);
Flock ($handle, lock_sh);
$filedata =fread ($handle, FileSize ($filename));
Fclose ($handle);
Than
File ($filename);
Be good at speed or stability

Current 1/2 Page 12 next page

The above describes the improvement of the speed of the mobile phone PHP optimization and efficient implementation of the problem 1th/2, including the speed of the mobile phone to improve the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.