A brief PHP performance note point

Source: Internet
Author: User
Tags php language
Simple PHP Performance Note points

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 more 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 point: PHP performance of built-in functions

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

$str = "Hello World";

Strlen ($STR) on the outside

for ($i =0; $i<>< p=""><>

Do something

}

?>

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 <<><><>< p=""><><><>

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

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