From C + + turn around, ask PHP initialization where? Is that the first time the program starts to read into the configuration data?

Source: Internet
Author: User
Tags server memory
For example, in C + + there is a main function, you can do some startup initialization, read into the configuration table what, just do it once
Now write the service side with PHP, this similar function I need to add where? Thanks, eh!


Reply to discussion (solution)

Just put it in the program!

Just put it in the program!



But a Web access, service side of the corresponding PHP will not run once? Isn't it a program that reads resources every time?? If PHP does not have the main function that starts, I want to create a global variable class that reads the resources under this class. This global variable must be executed only once?

Don't take it for granted!
Do you run two applications that you write in C + +, where the main function is only used once?

Don't take it for granted!
Do you run two applications that you write in C + +, where the main function is only used once?



Maybe I can not transfer from C + +, the Web server understanding is not in place Ah, next I understand:

For example, in C + +, start a service program, in the boot process to execute the main, and then the service program is always there, the next is to accept the client's various packets to handle;

So on PHP, I also feel that there should be something like this to provide an initialized service? For example, some of my configuration table is placed in MySQL, when it is started, it can only be read once to memory, can satisfy other Web requests. However, it seems that every time the client accesses a page, the corresponding PHP will be executed again. There's no sense in this.


Just put it in the program!



But a Web access, service side of the corresponding PHP will not run once? Isn't it a program that reads resources every time?? If PHP does not have the main function that starts, I want to create a global variable class that reads the resources under this class. This global variable must be executed only once?


Each client access is to reopen a program client if it corresponds to C + +.
In general, PHP global variables or programs to run are placed in a init.php file, which file needs to use these global configuration information can contain this file.
For the same access user (session is not expired, the general session is closed after the browser is expired), the user can use the session to store the relevant configuration options, so that users can access other pages directly from the session to get the user's configuration options.



Just put it in the program!



But a Web access, service side of the corresponding PHP will not run once? Isn't it a program that reads resources every time?? If PHP does not have the main function that starts, I want to create a global variable class that reads the resources under this class. This global variable must be executed only once?


Each client access is to reopen a program client if it corresponds to C + +.
In general, PHP global variables or programs to run are placed in a init.php file, which file needs to use these global configuration information can contain this file.
For the same access user (session is not expired, the general session is closed after the browser is expired), the user can use the session to store the relevant configuration options, so that users can access other pages directly from the session to get the user's configuration options.



So for example, the configuration I'm going to load is to read a list from MySQL. Even if there is a public init.php, each user's Web Access will contain this init.php, it is not still to go to MySQL every time to do a read it?

1, about the configuration of things you can study the more famous PHP development framework and the existing PHP open source programs, these frameworks in the initialization of the configuration is very good. 2, from the C/s architecture to the B/s architecture more difficult to convert the concept is the Web backend program survival cycle, you do C + + words can understand, your Web backend does not have while (true) such an infinite loop and blocking, run out of this instance is destroyed, if you want to leave your running state information, Running results, etc., you can only store your results in a special temporary file [session], this temporary file at some time, "This can be set, if not set the general user close the browser" will be destroyed, in the absence of destruction, you open the program again, You can read your running state by opening the temporary file, and then continue running at that point.
3, the Web back-end program generally for good user experience there will be a timeout limit, so there is no such as while (true) infinite loops.

PHP programs, like C + + desktop programs, initialize the environment every time you start
You should be able to understand that, right?

The so-called service program, is the resident memory program. It looks like it just needs to be initialized once.
If I start two of this service program (of course the program needs to be designed without conflict) then each program still has to complete its own initialization

PHP is a server-side script that is started by a Web server, so he does not reside in memory.
Which is why each call is initialized.




Just put it in the program!



But a Web access, service side of the corresponding PHP will not run once? Isn't it a program that reads resources every time?? If PHP does not have the main function that starts, I want to create a global variable class that reads the resources under this class. This global variable must be executed only once?


Each client access is to reopen a program client if it corresponds to C + +.
In general, PHP global variables or programs to run are placed in a init.php file, which file needs to use these global configuration information can contain this file.
For the same access user (session is not expired, the general session is closed after the browser is expired), the user can use the session to store the relevant configuration options, so that users can access other pages directly from the session to get the user's configuration options.



So for example, the configuration I'm going to load is to read a list from MySQL. Even if there is a public init.php, each user's Web Access will contain this init.php, it is not still to go to MySQL every time to do a read it?


This depends on you what the table, if it is the user's configuration information, not a lot of content can be stored with the session.
If it is data, according to the content of the data to be determined, some do the cache some can only read.

1, about the configuration of things you can study the more famous PHP development framework and the existing PHP open source programs, these frameworks in the initialization of the configuration is very good. 2, from the C/s architecture to the B/s architecture more difficult to convert the concept is the Web backend program survival cycle, you do C + + words can understand, your Web backend does not have while (true) such an infinite loop and blocking, run out of this instance is destroyed, if you want to leave your running state information, Running results, etc., you can only store your results in a special temporary file [session], this temporary file at some time, "This can be set, if not set the general user close the browser" will be destroyed, in the absence of destruction, you open the program again, You can read your running state by opening the temporary file, and then continue running at that point.
3, the Web back-end program generally for good user experience there will be a timeout limit, so there is no such as while (true) infinite loops.



Well, you're right, the two architectures are not quite the same on the life cycle, and I haven't turned around for a while.
that if in the B/s architecture, the kind of globally unique, as long as the initialization of the things put where? The session is also to use the same user as a unit it?

PHP programs, like C + + desktop programs, initialize the environment every time you start
You should be able to understand that, right?

The so-called service program, is the resident memory program. It looks like it just needs to be initialized once.
If I start two of this service program (of course the program needs to be designed without conflict) then each program still has to complete its own initialization

PHP is a server-side script that is started by a Web server, so he does not reside in memory.
Which is why each call is initialized.



I see. Is that PHP is just called a thing (such as a user access once), after the call to destroy it, right?

Right!
After the use of the next time, the stove


1, about the configuration of things you can study the more famous PHP development framework and the existing PHP open source programs, these frameworks in the initialization of the configuration is very good. 2, from the C/s architecture to the B/s architecture more difficult to convert the concept is the Web backend program survival cycle, you do C + + words can understand, your Web backend does not have while (true) such an infinite loop and blocking, run out of this instance is destroyed, if you want to leave your running state information, Running results, etc., you can only store your results in a special temporary file [session], this temporary file at some time, "This can be set, if not set the general user close the browser" will be destroyed, in the absence of destruction, you open the program again, You can read your running state by opening the temporary file, and then continue running at that point.
3, the Web back-end program generally for good user experience there will be a timeout limit, so there is no such as while (true) infinite loops.



Well, you're right, the two architectures are not quite the same on the life cycle, and I haven't turned around for a while.
that if in the B/s architecture, the kind of globally unique, as long as the initialization of the things put where? The session is also to use the same user as a unit it?


You say the only thing that is only initialized once.

Right!
After the use of the next time, the stove


Decisive and understandable, sharply.



1, about the configuration of things you can study the more famous PHP development framework and the existing PHP open source programs, these frameworks in the initialization of the configuration is very good. 2, from the C/s architecture to the B/s architecture more difficult to convert the concept is the Web backend program survival cycle, you do C + + words can understand, your Web backend does not have while (true) such an infinite loop and blocking, run out of this instance is destroyed, if you want to leave your running state information, Running results, etc., you can only store your results in a special temporary file [session], this temporary file at some time, "This can be set, if not set the general user close the browser" will be destroyed, in the absence of destruction, you open the program again, You can read your running state by opening the temporary file, and then continue running at that point.
3, the Web back-end program generally for good user experience there will be a timeout limit, so there is no such as while (true) infinite loops.



Well, you're right, the two architectures are not quite the same on the life cycle, and I haven't turned around for a while.
that if in the B/s architecture, the kind of globally unique, as long as the initialization of the things put where? The session is also to use the same user as a unit it?


You say the only thing that is only initialized once.



Like I said at the beginning, a list of configurations. This configuration table is inside MySQL. This allocation table is available to all users.
Through the discussion just now, I learned that PHP is "finished, the next time to use the stove again", so if this configuration code (query MySQL, and then make some adjustments) written in PHP, then the user every time you visit to execute PHP code.
Then, from C + +, the type of C/s architecture, when he started the S-side, there is a main function, and then run a configuration code in the main function, the configuration into the server memory, the other users to use, directly local calls.

So, I sent such a post ~ so I can only use some cache and so on to do?




1, about the configuration of things you can study the more famous PHP development framework and the existing PHP open source programs, these frameworks in the initialization of the configuration is very good. 2, from the C/s architecture to the B/s architecture more difficult to convert the concept is the Web backend program survival cycle, you do C + + words can understand, your Web backend does not have while (true) such an infinite loop and blocking, run out of this instance is destroyed, if you want to leave your running state information, Running results, etc., you can only store your results in a special temporary file [session], this temporary file at some time, "This can be set, if not set the general user close the browser" will be destroyed, in the absence of destruction, you open the program again, You can read your running state by opening the temporary file, and then continue running at that point.
3, the Web back-end program generally for good user experience there will be a timeout limit, so there is no such as while (true) infinite loops.



Well, you're right, the two architectures are not quite the same on the life cycle, and I haven't turned around for a while.
that if in the B/s architecture, the kind of globally unique, as long as the initialization of the things put where? The session is also to use the same user as a unit it?


You say the only thing that is only initialized once.



Like I said at the beginning, a list of configurations. This configuration table is inside MySQL. This allocation table is available to all users.
Through the discussion just now, I learned that PHP is "finished, the next time to use the stove again", so if this configuration code (query MySQL, and then make some adjustments) written in PHP, then the user every time you visit to execute PHP code.
Then, from C + +, the type of C/s architecture, when he started the S-side, there is a main function, and then run a configuration code in the main function, the configuration into the server memory, the other users to use, directly local calls.

So, I sent such a post ~ so I can only use some cache and so on to do?


Yes





1, about the configuration of things you can study the more famous PHP development framework and the existing PHP open source programs, these frameworks in the initialization of the configuration is very good. 2, from the C/s architecture to the B/s architecture more difficult to convert the concept is the Web backend program survival cycle, you do C + + words can understand, your Web backend does not have while (true) such an infinite loop and blocking, run out of this instance is destroyed, if you want to leave your running state information, Running results, etc., you can only store your results in a special temporary file [session], this temporary file at some time, "This can be set, if not set the general user close the browser" will be destroyed, in the absence of destruction, you open the program again, You can read your running state by opening the temporary file, and then continue running at that point.
3, the Web back-end program generally for good user experience there will be a timeout limit, so there is no such as while (true) infinite loops.



Well, you're right, the two architectures are not quite the same on the life cycle, and I haven't turned around for a while.
that if in the B/s architecture, the kind of globally unique, as long as the initialization of the things put where? The session is also to use the same user as a unit it?


You say the only thing that is only initialized once.



Like I said at the beginning, a list of configurations. This configuration table is inside MySQL. This allocation table is available to all users.
Through the discussion just now, I learned that PHP is "finished, the next time to use the stove again", so if this configuration code (query MySQL, and then make some adjustments) written in PHP, then the user every time you visit to execute PHP code.
Then, from C + +, the type of C/s architecture, when he started the S-side, there is a main function, and then run a configuration code in the main function, the configuration into the server memory, the other users to use, directly local calls.

So, I sent such a post ~ so I can only use some cache and so on to do?


Yes




Got it, huh. I first dropped directly in the PHP query, and so on when there is a performance bottleneck and then use some cache to go in.
  • Related Article

    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.