Jump to content

PHP above the root


themistral

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.