The global object instance of the C + + singleton pattern in the PHP extension is generated by multiple sub-processes destroyed, why? How to fix it

Source: Internet
Author: User
The global object instance of the C + + singleton pattern in the PHP extension is generated by multiple sub-processes destroyed, why??
In the PHP extension is a singleton mode of the global object, when the HTTP service stopped by the log to view and print the process number, found that the destructor is called multiple times, and is in a different process (through the process number observation). Why is that! Not that the HTTP service started once, my global object is instantiated once! How can the service stop when so many weird phenomena happen!

------Solution--------------------
How do you know that destructors are called multiple times? Is it also that you have been instantiated several times in the program?
------Solution--------------------
Who is responding to an HTTP request? Apache, IIS ...
What is PHP's position in HTTP requests? Applications for Web servers

Therefore, for each PHP-related HTTP request, a PHP input (line) will be triggered
Your extension is present in the dynamic link library and is independent in the input (line) path.

If you want your extended classes to be shared with each other, you have to modify the PHP kernel, but no matter what system it is, the kernel is not open source and is provided as a library.
------Solution--------------------
You PHP is a CGI run, it does not stop the construction and destruction, because each time is a new PHP interpreter process load a bunch of dynamic library, including your static C + + object, each PHP process load the same dynamic library, but their memory is isolated.

Landlord with fcgi to run PHP words will not be the same, only if the number of concurrent requests than the current number of fcgi processes will create a new fcgi process, but certainly not multi-process sharing.
------Solution--------------------
discuss

It was launched in Apache. If you say so, then I can't use the global object in my PHP extension! Dizzy!
Reference:

Who is responding to an HTTP request? Apache, IIS ...
What is PHP's position in HTTP requests? Applications for Web servers

Therefore, for each PHP-related HTTP request, a PHP input (line) will be triggered
Your extension is present in the dynamic link library and is independent in the input (line) path.
......
  • 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.