[FX.php List] A question about path when running cron jobs

Jonathan Schwartz jschwartz at exit445.com
Thu Sep 29 06:56:35 MDT 2011


Steve,

Thanks. This is what I was looking for. 

And thanks to Roger for the hardcover method. 

Jonathan Schwartz
Exit 445 Group
415-370-5011

On Sep 28, 2011, at 23:59, Steve Winter <steve at bluecrocodile.co.nz> wrote:

> Hi Jonathan
> 
> Try using:
> 
> $rootDir		= dirname(__FILE__);
> 
> This will set the variable to the full path (from system root) of the file which is being run. Then you can use things like
> 
> require_once($rootDir.'/config.php');
> require_once($rootDir.'/includes/somestuff.php');
> require_once($rootDir.'/../src/assets/includes/config.php');
> 
> To include/require other files and still have that relative to the script which is running, but fully referenced...
> 
> echo "$rootDir\n";
> /Library/WebServer/Documents/soloPress/webFleet
> echo "$rootDir/config.php\n";
> /Library/WebServer/Documents/soloPress/webFleet/config.php
> echo "$rootDir/../src/assets/includes/config.php\n";
> /Library/WebServer/Documents/soloPress/webFleet/../src/assets/includes/config.php
> echo file_exists($rootDir.'/../src/assets/includes/config.php'); 
> 1
> 
> Hope this helps...
> 
> Cheers
> Steve
> 
>> OK. That answers that question. Thanks.
>> 
>> Now, what is the best way to do this if my goal is to have transportable code with a single definition?  To be honest, path statements are not my strength.  In this particular case, the target folder (connections) is located outside of and at the same level of the web root.
>> 
>> Thanks,
>> 
>> J
>> 
>> At 3:46 PM -0700 9/28/11, david weiner wrote:
>>> Yes, you need to specify the full path for the cron version.
>>> 
>>> 
>>> On Sep 28, 2011, at 3:08 PM, Jonathan Schwartz wrote:
>>> 
>>>> Hi folks,
>>>> 
>>>> I am having trouble with paths when running php scripts using Cron in OS X server environment.
>>>> 
>>>> The scripts run fine if/when launched in development mode from a web browser.  However, when run from Cron, the script can not find files included with relative paths. For example:
>>>> 
>>>> include('../../Connections/connections.php');
>>>> 
>>>> I'm thinking that the context of the script is not the same when run in the two different environments.
>>>> 
>>>> Anyone know?
>>>> 
>>>> jonathan
>>>> 
>>>> --
>>>> Jonathan Schwartz
>>>> Exit 445 Group
>>>> jonathan at exit445.com
>>>> http://www.exit445.com
>>>> 415-370-5011
>>>> _______________________________________________
>>>> FX.php_List mailing list
>>>> FX.php_List at mail.iviking.org
>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>> 
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>> 
>> 
>> -- 
>> Jonathan Schwartz
>> Exit 445 Group
>> jonathan at exit445.com
>> http://www.exit445.com
>> 415-370-5011
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
> 
> Steve Winter
> +44 777 852 4776
> steve at bluecrocodile.co.nz
> 
> 
> 
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20110929/82888791/attachment-0001.html


More information about the FX.php_List mailing list