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 protected]', 'Before include', '', 'From:<[email protected]>'); // include the myriad class include($_SERVER['DOCUMENT_ROOT'].'/path/to/class'); mail('[email protected]', 'After include', '', 'From:<[email protected]>'); // initiate and instance of our class $obj = new class_name; $email = $obj->email; $file = $obj->file_name; mail('[email protected]', 'End of file', $email.' & '.$file, 'From:<[email protected]>'); 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? Link to comment https://forums.phpfreaks.com/topic/259335-php-above-the-root/ 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? Link to comment https://forums.phpfreaks.com/topic/259335-php-above-the-root/#findComment-1329397 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... Link to comment https://forums.phpfreaks.com/topic/259335-php-above-the-root/#findComment-1329420 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. Link to comment https://forums.phpfreaks.com/topic/259335-php-above-the-root/#findComment-1329427 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?" Link to comment https://forums.phpfreaks.com/topic/259335-php-above-the-root/#findComment-1329457 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 Link to comment https://forums.phpfreaks.com/topic/259335-php-above-the-root/#findComment-1329461 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. Link to comment https://forums.phpfreaks.com/topic/259335-php-above-the-root/#findComment-1329780 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). Link to comment https://forums.phpfreaks.com/topic/259335-php-above-the-root/#findComment-1329846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.