www.webdeveloper.com
Results 1 to 4 of 4

Thread: Cron Path Error

  1. #1
    Join Date
    May 2013
    Posts
    11

    Cron Path Error

    I am trying to execute cron but I am getting following errors :

    syntax error near unexpected token `"folder/file.php"'

    same program I could run if I put URL in browser instead of executing it through server.

    please help.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    When run via the CLI (as a cron job is) relative paths are relative the current working directory, not the directory of the script. Either use an absolute file system path within the script, have the cron job first change directory to that directory, or use chdir() within the script to change to its directory, e.g.:
    PHP Code:
    <?php
    chdir
    (__DIR__); // "magic" constant for this file's directory
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2007
    Location
    Tangerang, Banten
    Posts
    258
    There is an alternative for run php on cron:
    - call the site page using wget or curl.
    Example:
    Code:
    0 8 * * * /usr/bin/wget "http://127.0.0.1/cron.php" > /dev/null 2>&1
    0 8 * * * /usr/bin/curl -s "http://127.0.0.1/cron.php"
    To the people inside it will feel like an earthquake.
    That should knock out the Greco.
    And that's your exit strategy.

  4. #4
    Join Date
    Jun 2013
    Posts
    2
    Always use absolute paths when launching php scripts from cron.
    For example :

    0 0 * * * /usr/bin/php /var/www/mysite/script.php

    To get the absolute path in your cron scripts use the __FILE__ magic variable.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles