cron job to run php script with includes not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Annalyzer
    New Member
    • Aug 2007
    • 122

    cron job to run php script with includes not working

    I'm not positive that my problem is with the Linux end of this, but I'm pretty sure the php end is okay, so here goes:

    I need to run a php script with includes from a cron job on a remote (hosted) Linux server. The cron job:

    Code:
    /bin/sh /usr/www/users/warmsafe/event_mgr/admin/sh_scripts/cron-lynx.sh
    triggers ok - it runs a bash script called cron-lynx.sh that resides in the home/warmsafe/event_mgr/admin/sh_scripts folder. The bash script works too - it starts a php file called testcron.php located in home/warmsafe/event_mgr/admin. Testcron.php has an include that points up one level and then back down one level (../includes/mysql_connect.p hp). The first line in testcron.php (before <?php) is
    Code:
    #!/usr/local/bin/php
    which starts php if I'm understanding this correctly. Then, since php is being started from the php directory rather than running through Apache, I can't use the path that is configured in Apache, so I have to set the path on the fly. To do this I've got the command
    Code:
    ini_set("include_path", ".:/usr/lib/php:/usr/local/lib/php:/home/warmsafe/public_html/event_mgr/admin/")
    as the first command inside the <?php section of the file.

    The error message is:
    Code:
    : not found
    #!/usr/local/bin/php
    <br />
    <b>Warning</b>:  include(pages/mail_function.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in <b>/usr/www/users/warmsafe/event_mgr/admin/testcron.php</b> on line <b>9</b><br /> <br />
    <b>Warning</b>:  include() [<a href='function.include'>function.include</a>]: Failed opening 'pages/mail_function.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/warmsafe/public_html/event_mgr/admin') in <b>/usr/www/users/warmsafe/event_mgr/admin/testcron.php</b> on line <b>9</b><br /> <br /> <b>Fatal error</b>:  Call to undefined function mail_attachment() in <b>/usr/www/users/warmsafe/event_mgr/admin/testcron.php</b> on line <b>17</b><br />
    I think the problem lies in the placement of the bash script, but I'm not sure if that's in relation to the php file or or to the /bin/sh directory or what? And why doesn't the ini_set statement make that a moot point anyway? My Linux is pretty rusty, so I beg your patience as well as your assistance.
    Last edited by Annalyzer; May 8 '10, 02:21 AM. Reason: misspelled word in title
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    PHP is still php. Just because the script is located outside of the apache structure, doesn't mean that PHP doesn't know what its default path is.

    I just created this basic script:

    Code:
    #!/usr/bin/php
    
    <?php
        echo "This is only a test of PHP on cli!\n";
    ?>
    If you run that from the command line, it outputs to the screen just what you see. Take out the ini definition stuff and create the script the way you normally would.

    BTW, the first line, the "shebang" line as it is affectionately referred, tells the OS where to find the interpreter that will be used to run the code enclosed in the script.

    Regards,

    Jeff

    Comment

    Working...