Notice the simple PHP performance optimization note, notice PHP performance Optimization _php Tutorial

Source: Internet
Author: User
Tags benchmark php performance tuning what php

Notice the simple PHP performance optimization note, the PHP performance optimization


What happens, you may experience performance issues:

Improper use of 1.php syntax
2. Use the PHP language to do what it is not good at
3. A service that is connected in PHP language does not give force
4.php of its own short board
5. I do not know the question

General: PHP performance issues not exceeding One-second (general 30%~40%)

PHP Performance Problem Resolution direction:

PHP language-level performance optimization->php performance optimization of peripheral problems (connected services, network environment)->php Language self-analysis and optimization

(PHP language level)

Optimization point: Write less code, use PHP's own ability

Problem: More self-written code redundancy, poor readability, resulting in low performance
Why Low: PHP code needs to be compiled to parse into the underlying language, the process of each request will be processed once, the cost is large
Method: Use PHP built-in variables, constants, functions

Optimization points: PHP built-in function performance advantages and disadvantages

Case Description: PHP built-in functions, there are still differences between the speed
Recommendation: Learn more about the time complexity of PHP built-in functions

Optimize points: Use as few magical functions as possible

Scenario Description: PHP provides a magic function that is poorly performing
Why low performance: In order for PHP programmers to save trouble, PHP language for you to do a lot of
A good way: Avoid using PHP magic functions as much as possible

Optimization point: Error suppressor that generates additional overhead

Actual logic: Before the code starts, set the highest error level, after the end, then reply to set the error level. Add opcode, ignore error

Optimize points: Use memory appropriately

Case Description: PHP has a guaranteed memory recovery mechanism, but please also use memory carefully
Recommendation: Use Unset () to release the non-applicable memory in a timely manner (note: unset () occurs when the logoff is not lost)

Optimize points: Use regular expressions as little as possible

Description: The retrospective overhead of the expression is large, "no diamond do not embrace the ceramic live"
Recommendation: Use string processing functions to implement the same logic

Optimization points: Avoid doing operations within loops

Description: Calculation in the loop will be repeated

<?php$str= "Hello World"; A//strlen ($STR) is placed outside for ($i =0; $i
 
  

Optimize points: Reduce compute-intensive business

Scenario Description: PHP is not suitable for intensive computing scenarios

Why? PHP language features determine PHP is not suitable for large data-volume operations
PHP fit Scenario: Fits webserver and backend services, UI rendering

Optimization points: Be sure to use quoted strings for key values

Case Description: PHP will use a key value without quotation marks as a constant, generating the cost of finding a constant
Recommendation: Use quotation marks strictly as key values

--------------------------------------------

(Performance optimization for PHP peripheral issues)-

Operating environment, file storage, database, cache, network

Reduce File class operations

Cost order for common PHP scenarios:
Read and write disks, read and write databases, read and write memory, read and write network data
Read/write Memory <<><><>

Optimize Network Requests

Pit of Network request:

1. Uncertainties in the interface of the other party

2. Network stability

How do I optimize network requests?

1. Set timeout period

A) connection Timeout 200ms
b) Read Timeout 800ms
c) Write timeout 500ms

2. Parallelization of Serial requests

A) using curl_multi_* ()
b) using Swoole extensions

Compressed PHP interface output

Cache Duplicate Compute Content

What happens when the output content is cached?

Multiple requests, the content does not change the situation

Overlapping time window thought

Bypass scheme

Analyze PHP self-analysis and optimization:

Testing with tools

PHP Performance Bottlenecks Workaround:
Opcode cache (last link in code compilation) PHP extension APC does Opcode cache

Supplemental stress test Software instructions for use:

Ab-h

Apache Benchmark (AB) is a stress test software provided by Apache that comes with the beta software when installing Apache servers

Use:./ab-n1000-c100 http://www.baidu.com/

-N Request number-c concurrent Number URL target pressure-measured address

The above content to introduce the simple PHP performance optimization attention point, I hope this article sharing can help everyone.

Articles you may be interested in:

    • Some ways to optimize PHP efficiency and improve PHP performance
    • PHP Performance Optimization analysis tool xdebug large Web site Debugging tools
    • PHP performance optimization generates highly optimized code
    • PHP Performance Tuning Tool benchmark class debug execution time
    • Performance optimization tips for the lamp server PHP
    • 50 Ways to optimize PHP program performance
    • PHP Import a lot of data to MySQL performance optimization tips

http://www.bkjia.com/PHPjc/1088788.html www.bkjia.com true http://www.bkjia.com/PHPjc/1088788.html techarticle Notice the simple PHP performance optimization Note, it is important to know what PHP performance optimization, you may encounter performance issues: 1.php syntax inappropriate use 2. Use PHP language to do what it is not good at ...

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