Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Execute the script via the console, not the web server.</p> <p>The cron could look like this:</p> <pre><code>*/5 * * * * php -f /path/to/cron.php </code></pre> <p>Then the file could do this:</p> <pre><code>cron.php: &lt;?php if ( array_key_exists('REMOTE_ADDR', $_SERVER) ) die("Can only be run from the command line!"); </code></pre> <p>That will guarantee it's only run by the server.</p> <p><strong>Edit in response to comments</strong></p> <p>You can't get to a public folder inside a private folder, in general, and if you can't add new directories outside the web root, your cache dir will have to be protected another way.</p> <p>I'm going to assume all your files are in the web root, ie: <code>/home/site/publichtml</code>. Replace that with whatever your directory is.</p> <p>Create a new directory <code>/home/site/publichtml/.cache</code>. Add the following as a .htaccess file:</p> <pre><code>Deny from all </code></pre> <p>Now your scripts should be able to access the folder from the file system, but it's inaccessible via the web server.</p> <p>If you can set up a cron job on the server (via the web admin or another way, it sounds like you can) do it as above, ie: Use <code>php -f /home/site/publichtml/cron.php</code> as the command, and include the check for the array key.</p> <p>Alternatively, you can check like this:</p> <pre><code>if ( !isset($_SERVER['argc']) ) die("Must be run from the command line!\n"); </code></pre> <p><code>$_SERVER['argc']</code> is only set when the script is executed from the command line.</p> <p>If you can keep the cron script out of the web root, good. If not, that should be secure.</p> <p>Finally, to get rid of the E_NOTICES, add this to the top of the cron.php:</p> <pre><code>error_reporting(E_ALL ^ E_NOTICE); // Turn off notices </code></pre> <p>or</p> <pre><code>error_reporting(0); // Hide all error reporting </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload