Home Backend Development PHP Tutorial Summary of PHP optimization and efficient speed-up issues_PHP tutorial

Summary of PHP optimization and efficient speed-up issues_PHP tutorial

Jul 20, 2016 am 11:05 AM
global php return one optimization transfer use function exist speed up array hour Compare want question Efficient

1. In a function, using return when passing an array is more efficient than using global, 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
2. (This code is used to get the program URL corresponding to the directory, 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 better than
$pre_urlarray= explode('/',$HTTP_SERVER_VARS['HTTP_REFERER']);
$pre_url=array_pop($pre_urlarray);

To be efficient
3. When judging in a loop, use constant for numerical judgment Equality is better than equal efficiency
 $a=2;$b=2;
For example
if($a==$b)$c=$a;
>than
if($ a===$b)$c=$a;

Efficient
4. Try to use where in when querying mysql and use limit less
Limit checks the first few records of multiple records, which is very fast , but querying the top few items will be slow
Use in. When querying continuous records, it is very fast. The first run of non-continuous records will be a little slower, but it will be faster after that!
5. NT The stability of server data operation is not as good as unix/linux
6. Try to use ob_start() before output; it can speed up the output, suitable for NT or nuli/linux. For unlix servers, if you use ob_start('ob_gzhandler'); the output efficiency Will be higher
7. When judging, try to use if ($a==his value). When negating, try to use if (empty ($a)), because this way the program runs faster


8. The efficiency of using != is equivalent to <> There is a big difference
10. Using standardized SQL statements will facilitate MySQL parsing
11. Use
if($online){
$online1=$online;
setcookie ('online1',$online,$cookietime,$ckpath,$ckdomain,$secure);
}

COOKIE will take effect immediately
Use
if($online)


http://www.bkjia.com/PHPjc/445144.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445144.htmlTechArticle1. In a function, using return when passing an array is more efficient than using global, for example: function userloginfo($usertemp ){ $detail=explode(|,$usertemp); return $detail; } $login=userl...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

See all articles