themistral Posted March 20, 2012 Share Posted March 20, 2012 Hi guys, I've got a simple script that I'm running from a folder above the root (as a cron job). I've tried the script in the httpdocs folder and it works fine. mail('email@example.com', 'Before include', '', 'From:<email@example.com>'); // include the myriad class include($_SERVER['DOCUMENT_ROOT'].'/path/to/class'); mail('email@example.com', 'After include', '', 'From:<email@example.com>'); // initiate and instance of our class $obj = new class_name; $email = $obj->email; $file = $obj->file_name; mail('email@example.com', 'End of file', $email.' & '.$file, 'From:<email@example.com>'); If I run this file in httpdocs, it's fine and I get all emails. If I run this from 1 folder above the root (from a cron job), I get the first 2 emails but not the last one, suggesting that the include hasn't worked. Could this be a permissions problem? I have tried running the cron job as both root and apache and changed the owner/group of the script to match. Is there a reason why includes won't work above the root? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted March 20, 2012 Share Posted March 20, 2012 how about trying some error capture in the script and seeing what comes back? Quote Link to comment Share on other sites More sharing options...
requinix Posted March 20, 2012 Share Posted March 20, 2012 Most of the familiar stuff in $_SERVER isn't available if you're running the script from a command line (such as through a cron job). For example, DOCUMENT_ROOT tends to be empty... Quote Link to comment Share on other sites More sharing options...
creata.physics Posted March 20, 2012 Share Posted March 20, 2012 Would the cron read __FILE__ then? I was thinking using: include( dirname( __FILE__ ) . '/path/to/class'); Would correct the issue, but I'm not sure now..I know it's just a magic constant and not a super global so I figured that'd work. Quote Link to comment Share on other sites More sharing options...
requinix Posted March 20, 2012 Share Posted March 20, 2012 PHP has to get its information from somewhere. A lot of the stuff you know about is available because PHP runs as a server module or CGI application: DOCUMENT_ROOT, SCRIPT_NAME, HTTP_HOST, and so on. Thus when PHP doesn't run as a module or through CGI you lose it. So think about that. "Is this thing I want available because PHP is running as a webpage? Or can PHP figure it out independently?" Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted March 20, 2012 Share Posted March 20, 2012 why dont you try the absolute path to the file depending on your server setup home/account/htttpdocs/path/to/class of coarse change all that to suit your hosting folder tree Quote Link to comment Share on other sites More sharing options...
themistral Posted March 21, 2012 Author Share Posted March 21, 2012 Thanks for the help guys. dragon_sa I'm going to have to do that I think - I wanted to avoid it as this script is going across multiple sites. Quote Link to comment Share on other sites More sharing options...
kicken Posted March 21, 2012 Share Posted March 21, 2012 Would the cron read __FILE__ then? __FILE__ (or __DIR__ in 5.3) will work from within a CLI environment yes. You can use these as an alternative for DOCUMENT_ROOT generally. I typically use these to define my own DOCUMENT_ROOT constant which will always be available (regardless of web or cli). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.