php性能优化
你的团队成员提出,这些年php引擎已经有很多象征性的性能提升。如果你的web server仍然运行着比较老的版本,如php3或者php4。那么在你尝试着优化你代码之前,应该先深入调查一下版本之间的升级情况。
点击以下链接,可以了解具体细节:
- 输出缓存控制
class dog { public $name = ''; public function setName($name) { $this->name = $name; } public function getName() { return $this->name; } }
注意:setName()和getName()除了存储和返回name属性外,没做任何工作。
$rover = new dog(); $rover->setName('rover'); echo $rover->getName();
直接设置和访问name属性,性能能提升100%,而且也能缩减开发时间!
$rover = new dog(); $rover->name = 'rover'; echo $rover->name;
$description = strip_tags($_POST['description']); echo $description;
echo strip_tags($_POST['description']);
foreach ($userList as $user) { $query = 'INSERT INTO users (first_name,last_name) VALUES("' . $user['first_name'] . '", "' . $user['last_name'] . '")'; mysql_query($query); }
过程:
INSERT INTO users (first_name,last_name) VALUES("John", "Doe")
替换这种循环方案,你能够拼接数据成为一个单一的数据库操作。
$userData = array(); foreach ($userList as $user) { $userData[] = '("' . $user['first_name'] . '", "' . $user['last_name'] . '")'; } $query = 'INSERT INTO users (first_name,last_name) VALUES' . implode(',', $userData); mysql_query($query);
过程:
INSERT INTO users (first_name,last_name) VALUES("John", "Doe"),("Jane", "Doe")...
- MySQL INSERT Syntax
- PHP Memcache module
- Smarty templating engine
- http://3v4l.org --- 分析各个版本间的代码执行效率,非常不错的网站
- http://www.php-internals.com/ ———研究php内核的网站!


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
