title: Background PHP Process with shell_exec() As Part of WordPress Plugin
body: <p>I'm trying to run a background PHP process with <code>shell_exec()</code> as a part of WordPress plugin.</p>
  
  <p>This is the sample.</p>
  
  <pre><code>/* Plugin Name: Sample Background Process */
  
  add_action('init', 'Sample_Background_Process');    
  function Sample_Background_Process() {
      $file = __DIR__ . '/log.html';
      $current = date('l jS \of F Y h:i:s A') . ': accessed&lt;br /&gt;';
      file_put_contents($file, $current, FILE_APPEND);
  }
  </code></pre>
  
  <p>It creates a log in the plugin folder and whenever a page gets access it appends some text to it.</p>
  
  <p>Then, I added this line, <code>shell_exec('php "' . ABSPATH . '/index.php" &gt; /dev/null 2&gt;/dev/null &amp;');</code>. So a background process should access the page and run the function which appends text to the log file. But it doesn't seem to be doing it. I expect one page load produces two lines in the log file. But it only adds one line, which means a background process is not run or WordPress does not do anything if it is called like this.</p>
  
  <pre><code>add_action('init', 'Sample_Background_Process');    
  function Sample_Background_Process() {
      $file = __DIR__ . '/log.html';
      $current = date('l jS \of F Y h:i:s A') . ': accessed&lt;br /&gt;';
      file_put_contents($file, $current, FILE_APPEND);
      shell_exec('php "' . ABSPATH . '/index.php" &gt; /dev/null 2&gt;/dev/null &amp;');
  }
  </code></pre>
  
  <p>What am I doing wrong? </p>
  
  <p>The path, <code>php</code> in <code>shell_exec()</code> is altered by the path to php.exe in my actual script since I'm testing on Windows server. It runs fine in other PHP scripts.</p>
  
  <p>Thanks.</p>