title: How to let PHP keep reload same file
body: <p><strong>Background:</strong></p>
  <p>I designed a website and made a single access point, <code>index.php</code>. So I could do some global settings there. And <code>index.php</code> file will parse request URI and load the required file fro clients. Here is an example of <code>index.php</code> file below.</p>
  <pre><code>&lt;?php
  
  if (!defined('MINUTE_IN_SECONDS')) {
      define( 'MINUTE_IN_SECONDS', 60 );
  }
  // ... more constants
  
  require_once 'functions/lib/utility.php';
  // ... more require files
  
  /**
   * Load other page content. 
   */
  if($_SERVER['REQUEST_URI'] !== $_SERVER['PHP_SELF']){
      $route = new Route();
      $page = $route-&gt;guessUrl('URI');
  
      if(!empty($page) &amp;&amp; $page != $_SERVER['PHP_SELF']){
          $page = './' .ltrim($page, '/');
          if(file_exists($page)){
              include_once $page; // put required file content in buffer
          }else{
              http_response_code(404);
          }
          // exit;
      }
  }
  </code></pre>
  <p><strong>Question:</strong></p>
  <p>The website works fine under Apache. But after I moved it to Swoole HTTP server, I got a problem that I could not solve.</p>
  <p>In Swoole request handler function, I followed the same design and passed all the requests to <code>index.php</code> file. Then <code>index.php</code> file will use the code above to locate the required file and return the content in output buffer. Here is an example of Swoole request handler function.</p>
  <pre><code>    public function getResponseContent(){
          $content = '';
  
          try {
              ob_start(&quot;ob_gzhandler&quot;);
              $file = $_SERVER['DOCUMENT_ROOT'] .$_SERVER['PHP_SELF'];
              $type = pathinfo($file, PATHINFO_EXTENSION);
              if(empty($type) || strtolower($type) == 'php'){
                  $file = $_SERVER['DOCUMENT_ROOT'] .'/index.php';
              }
  
              include_once $file; // How to keep reload index.php ?
              
          } catch (Exception $e) {
              error_log($e-&gt;getMessage());
          } finally { 
              $content = ob_get_clean();
          }
  
          return $content;
      }
  </code></pre>
  <p>From the code above, you could see that if a required file is a PHP file, request is passed to <code>index.php</code> file; and if a file is a static file, e.g. a css file, we directly get static file content.</p>
  <p>So now when I visit the website, I entered <code>http(s)://website.com/home.php</code>. Because this is the first time to load the <code>index.php</code> file in Swoole, it is fine, I could see the page correctly in browser. But when I went to another page, e.g. <code>http(s)://website.com/service.php</code>, the Swoole HTTP server will need to include the index.php file again. Then, this time the <code>getResponseContent</code> function returned nothing. No content in buffer at all. I could not load index.php file in buffer again.</p>
  <p><strong>I tried to fix this, but failed.</strong></p>
  <p>My first feeling is error should be about <code>include_once</code>. So I changed the <code>include_once</code> to <code>include</code>, and I got the same issue. I tried to use <code>require</code>, I got the same issue again.</p>
  <p>By the way, my php version is 7.4.3 and Swoole version is openswoole 4.10.0</p>
  <p><strong>Please help. Any feedback is appreciated.</strong></p>
  <p><strong>Update</strong></p>
  <p>After struggling for a few days, I have to ask Swoole team about it. And here is the reply. <a href="https://github.com/swoole/swoole-src/issues/4605" rel="nofollow noreferrer">https://github.com/swoole/swoole-src/issues/4605</a></p>
  <p>Wrap the file inside a function did work for this situation.</p>
  <p>By the way, while working on this issue, I found an interesting thing. Openswoole and Swoole is not same thing now. They are separate project. When reading openswoole document online, I thought Swoole has change the name to openswoole after v4.7.1. But the truth is Swoole is still developing itself. Now its version is v4.8.x. Just a reminder for everyone. Don't post questions/issues to the wrong GitHub repository.</p>