Jump to content

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@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?

Link to comment
https://forums.phpfreaks.com/topic/259335-php-above-the-root/
Share on other sites

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.