Home  >  Article  >  Backend Development  >  When do php static methods start taking up memory? Will different php processes share static methods?

When do php static methods start taking up memory? Will different php processes share static methods?

WBOY
WBOYOriginal
2016-09-15 11:15:071582browse

When do php static methods start taking up memory?

For example, a class

<code>class Test {
    public static function test1(){}
    public static function test2(){}
    ...
}
</code>

I considered the following situations:

  1. When executing php code, static methods are scanned, regardless of whether they are included., they are too inefficient and should not be used.

  2. When I include 'Test.php', will it scan the class and load the static method into the memory? At this time, all methods should be loaded into memory.

  3. If 2 is not true, should it be loaded into the memory when calling the method Test::test1();? If loaded at this time, should only the current method be loaded, or all static methods of the current class?


Will different php processes share static methods?

As shown below

When do php static methods start taking up memory? Will different php processes share static methods?

Here is a master who talked about Nginx and Php-fpm processes and threads: https://segmentfault.com/q/10...

If this is the case, one Php-fpm process serves one client, but if the concurrency is too high, won't there be many processes? In terms of process communication, requests from different clients belong to different processes and should not affect each other. There should be a cache of static methods in the memory occupied by the process. However, if a client has multiple requests, read the article. It is a blocking single-thread model, so each request should wait until the last request is completed before starting execution. Will the cache of the static method be cleared at this time, or should it continue to be saved? If cleared, static methods should not be shared.

Statement:
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