Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Wordpress initialization scripts run every time a request hits the server?

Tags:

php

wordpress

The index.php file in my Wordpress installation directory seems to run several other scripts in order to properly configure the Wordpress Environment, and in turn, these scripts define several constants. My question is: does that procedure of running the initialization scripts and defining constants happens every time a requests hits the server, or does it happens only after the first request to the server and these environment constants and settings remain defined until the server is shutdown?

like image 582
Lhaer Avatar asked Sep 05 '26 01:09

Lhaer


1 Answers

In Wordpress (and PHP in general), each request runs in its own environment, that is isolated from other requests and does not share any constants, variables or loaded classes with other requests. Each request starts with a "clean slate" and has to do all initialization work from new. When the request finishes, all data loaded/created by the request is destroyed.

There are some exceptions to the "total isolation of requests" rule:

  • PHP's Opcode cache stores the result of parsing a PHP file in shared memory. When the same file is loaded in a later request, the parsing step can be skipped.
  • Sessions preserve some state between requests.
like image 171
Dennis B. Avatar answered Sep 07 '26 15:09

Dennis B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!