Table of Contents
提高PHP编程效率的20个要点,php编程效率要点
Home php教程 php手册 提高PHP编程效率的20个要点,php编程效率要点

提高PHP编程效率的20个要点,php编程效率要点

Jun 13, 2016 am 08:55 AM
web development

提高PHP编程效率的20个要点,php编程效率要点

用单引号代替双引号来包含字符串,这样做会更快一些。因为PHP会在双引号包围的字符串中搜寻变量,单引号则 不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的“函数”(译注:PHP手册中说echo是语言结构,不是真正的函数,故把函数加 上了双引号)。

     1、如果能将类的方法定义成static,就尽量定义成static,它的速度会提升将近4倍。

        2、$row[’id’] 的速度是$row[id]的7倍。

  3、echo 比 print 快,并且使用echo的多重参数(译注:指用逗号而不是句点)代替字符串连接,比如echo $str1,$str2。

  4、在执行for循环之前确定最大循环数,不要每循环一次都计算最大值,最好运用foreach代替。

  5、注销那些不用的变量尤其是大数组,以便释放内存。

  6、尽量避免使用__get,__set,__autoload。

  7、require_once()代价昂贵。

  8、include文件时尽量使用绝对路径,因为它避免了PHP去include_path里查找文件的速度,解析操作系统路径所需的时间会更少。

  9、如果你想知道脚本开始执行(译注:即服务器端收到客户端请求)的时刻,使用$_SERVER[‘REQUEST_TIME’]要好于time()。

  10、函数代替正则表达式完成相同功能。

  11、str_replace函数比preg_replace函数快,但strtr函数的效率是str_replace函数的四倍。

  12、如果一个字符串替换函数,可接受数组或字符作为参数,并且参数长度不太长,那么可以考虑额外写一段替换代码,使得每次传递参数是一个字符,而不是只写一行代码接受数组作为查询和替换的参数。

  13、使用选择分支语句(译注:即switch case)好于使用多个if,else if语句。

  14、用@屏蔽错误消息的做法非常低效,极其低效。

  15、打开apache的mod_deflate模块,可以提高网页的浏览速度。

  16、数据库连接当使用完毕时应关掉,不要用长连接。

  17、错误消息代价昂贵。

  18、在方法中递增局部变量,速度是最快的。几乎与在函数中调用局部变量的速度相当。

  19、递增一个全局变量要比递增一个局部变量慢2倍。

  20、递增一个对象属性(如:$this->prop++)要比递增一个局部变量慢3倍。

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 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)

Python web development framework comparison: Django vs Flask vs FastAPI Python web development framework comparison: Django vs Flask vs FastAPI Sep 28, 2023 am 09:18 AM

Python web development framework comparison: DjangovsFlaskvsFastAPI Introduction: In Python, a popular programming language, there are many excellent web development frameworks to choose from. This article will focus on comparing three popular Python web frameworks: Django, Flask and FastAPI. By comparing their features, usage scenarios and code examples, it helps readers better choose the framework that suits their project needs. 1. Django

How to use the Twig template engine in PHP for web development How to use the Twig template engine in PHP for web development Jun 25, 2023 pm 04:03 PM

With the continuous development of Web development technology, more and more developers are beginning to look for more flexible and efficient template engines to develop Web applications. Among them, Twig is a very excellent and popular PHP template engine. It is developed based on the Symfony framework and supports unlimited expansion. It is very suitable for building complex web applications. This article will introduce how to use the Twig template engine for web development in PHP. 1. Introduction to Twig template engine Twig is developed by FabienPoten

Reimagining Architecture: Using WordPress for Web Application Development Reimagining Architecture: Using WordPress for Web Application Development Sep 01, 2023 pm 08:25 PM

In this series, we will discuss how to build web applications using WordPress. Although this is not a technical series where we will look at code, we cover topics such as frameworks, fundamentals, design patterns, architecture, and more. If you haven’t read the first article in the series, I recommend it; however, for the purposes of this article, we can summarize the previous article as follows: In short, software can be built on frameworks, software can Extend the base. Simply put, we distinguish between framework and foundation—two terms that are often used interchangeably in software, even though they are not the same thing. WordPress is a foundation because it is an application in itself. It's not a framework. For this reason, when it comes to WordPress

MySQL and PostgreSQL: Best Practices in Web Development MySQL and PostgreSQL: Best Practices in Web Development Jul 14, 2023 pm 02:34 PM

MySQL and PostgreSQL: Best Practices in Web Development Introduction: In the modern world of web development, databases are an essential component. When choosing a database, common choices are MySQL and PostgreSQL. This article will cover best practices for using MySQL and PostgreSQL in web development and provide some code examples. 1. Applicable scenarios MySQL is suitable for most web applications, especially those that require high performance, scalability and ease of use.

What are the advantages and disadvantages of C++ compared to other web development languages? What are the advantages and disadvantages of C++ compared to other web development languages? Jun 03, 2024 pm 12:11 PM

The advantages of C++ in web development include speed, performance, and low-level access, while limitations include a steep learning curve and memory management requirements. When choosing a web development language, developers should consider the advantages and limitations of C++ based on application needs.

What are the common application scenarios of Golang in software development? What are the common application scenarios of Golang in software development? Dec 28, 2023 am 08:39 AM

As a development language, Golang has the characteristics of simplicity, efficiency, and strong concurrency performance, so it has a wide range of application scenarios in software development. Some common application scenarios are introduced below. Network programming Golang is excellent in network programming and is particularly suitable for building high-concurrency and high-performance servers. It provides a rich network library, and developers can easily program TCP, HTTP, WebSocket and other protocols. Golang's Goroutine mechanism allows developers to easily program

The balance of hard and soft skills required for Python developers The balance of hard and soft skills required for Python developers Sep 10, 2023 am 11:40 AM

Python is one of the most popular programming languages ​​today, attracting many developers to join the Python development field. However, to be an excellent Python developer requires not only mastering the hard skills of the programming language, but also certain soft skills. This article will explore how Python developers can strike a balance between hard and soft skills. In the world of Python development, hard skills refer to the technical and programming knowledge required by developers. The Python language itself is simple, flexible, easy to learn and use,

Remote development skills in Python web development Remote development skills in Python web development Jun 18, 2023 pm 03:06 PM

As one of the most popular programming languages ​​at present, Python is performing increasingly well, especially in the field of web development. In order to improve development efficiency, many developers like to use remote development technology. So in Python Web development, how can we use remote development technology to improve development efficiency? 1. Selection of remote development environment For remote development in Python Web development, we first need to choose a suitable remote development environment. Common remote development technologies include the following: Remote SSHSSH is Lin

See all articles