title: Ideology query: reconstructive vs pre-loaded method on PHP
body: <p>Well, I do not know if I can post something like this here. But I'm pretty sure all this is the correct place where we can discuss new ideas to improve our knowledge. Right?</p>
  
  <p>I was thinking about this: when using PHP as an APACHE module, each request to a PHP file generate a new process to run your code. Generally we load multiple files (<code>include</code>'s) and perform various procedures as well. So guess where we ran a "index.php" the whole process is repeated several times and several whenever necessary.</p>
  
  <p>A pratical example: if we ran a specific index.php that load 10 classes, PHP will parse all files and execute interesting parts, if need. It'll generate an I/O usage, of CPU, Memory and Storage.</p>
  
  <pre><code>&lt;?php
  
      require_once 'classes/File.php';
      require_once 'classes/Event.php';
      require_once 'classes/Mobile.php';
      // ...
  
      File::emptyDir('tmp');
  
  ?&gt;
  </code></pre>
  
  <p>It'll load every classes, parse and execute it. Ok.</p>
  
  <p>So, in an ambient that I not need execute the required file too many times, just once, and only uses your methods, if I create a socket ambient to use that to each user request, can overspeed PHP access by avoid redundances?</p>
  
  <p>A simple example of an user interation:</p>
  
  <ol>
  <li>User start a request <code>/page?version=1.3</code>.</li>
  <li>The <code>.htaccess</code> redirect to <code>request.php</code> engine.</li>
  <li>The engine check if exists an idle pre-loaded service (<code>service.php</code>'s socket) and use that. If do not, start a new service (pre-load your code) and use that.</li>
  <li>Send user data (as <code>$_SERVER</code> and <code>$_GET</code>) to service (as JSON for instance), it will turn to WORKING state.</li>
  <li>Service will return user data to <code>request.php</code> again. And turn it to IDLE to be used in the next request. And will close after a very long IDLE time.</li>
  </ol>
  
  <p>The question is: this method can overspeed PHP, by avoid parse all code everytime (excluding opcode optimizer), preparing classes, etc.?</p>
  
  <p>I think about some theorical de/advantages:</p>
  
  <ul>
  <li>GOOD: possibly will turn request very fast;</li>
  <li>GOOD: will avoid load every time the same file, or create a new process everytime;</li>
  <li>GOOD: will be possible to control every thread instances and your states;</li>
  <li>NEUTRAL: if you change some file, you need close all services to create a new with updated files. Solution: just avoid that, in a devopment ambient, every main request will start a new service.</li>
  <li>BAD: will use memory for more time, instead of free that after every request;</li>
  </ul>