Reading SCRIPT_FILENAME thru cron

This is a discussion on Reading SCRIPT_FILENAME thru cron within the PHP Language forums, part of the PHP Programming Forums category; hi I am using PHP 5.0.4 on OpenSuse 10.x. I have the following piece of code, $sp1 = $...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-24-2006
BG Mahesh
 
Posts: n/a
Default Reading SCRIPT_FILENAME thru cron


hi

I am using PHP 5.0.4 on OpenSuse 10.x. I have the following piece of
code,

$sp1 = $_SERVER["SCRIPT_FILENAME"];

$sp1 is set correctly when I execute file.php thru the browser. But
when I run that script thru cron [as root] $sp1 is always null.

But on Redhat we see that $sp1 has value [when file.php is executed
thru cron].

We don't see any error messages on OpenSuse. What could we be doing
wrong? Any pointers are appreciated

B.G. Mahesh

Reply With Quote
  #2 (permalink)  
Old 07-24-2006
Alvaro G. Vicario
 
Posts: n/a
Default Re: Reading SCRIPT_FILENAME thru cron

*** BG Mahesh escribió/wrote (24 Jul 2006 08:23:36 -0700):
> I am using PHP 5.0.4 on OpenSuse 10.x. I have the following piece of
> code,
>
> $sp1 = $_SERVER["SCRIPT_FILENAME"];
>
> $sp1 is set correctly when I execute file.php thru the browser. But
> when I run that script thru cron [as root] $sp1 is always null.
>
> But on Redhat we see that $sp1 has value [when file.php is executed
> thru cron].


From PHP manual:

$_SERVER is an array containing information such as headers, paths, and
script locations. The entries in this array are created by the webserver.
There is no guarantee that every webserver will provide any of these;
servers may omit some, or provide others not listed here. That said, a
large number of these variables are accounted for in the » CGI 1.1
specification, so you should be able to expect those.

The "webserver" thing is a typo, but it's true that available variables
differ depending on where you execute the script. I suggest you try this
code:

<?

print_r($_SERVER);

?>


It'll tell you what variables you can use.

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Reply With Quote
  #3 (permalink)  
Old 07-24-2006
Alvaro G. Vicario
 
Posts: n/a
Default Re: Reading SCRIPT_FILENAME thru cron

*** Alvaro G. Vicario escribió/wrote (Mon, 24 Jul 2006 21:47:02 +0200):
> <?
>
> print_r($_SERVER);
>
> ?>


See also:

print_r(__FILE__);


--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Reply With Quote
  #4 (permalink)  
Old 07-25-2006
BG Mahesh
 
Posts: n/a
Default Re: Reading SCRIPT_FILENAME thru cron


Alvaro G. Vicario wrote:
> *** BG Mahesh escribió/wrote (24 Jul 2006 08:23:36 -0700):
> > I am using PHP 5.0.4 on OpenSuse 10.x. I have the following piece of
> > code,
> >
> > $sp1 = $_SERVER["SCRIPT_FILENAME"];
> >
> > $sp1 is set correctly when I execute file.php thru the browser. But
> > when I run that script thru cron [as root] $sp1 is always null.
> >
> > But on Redhat we see that $sp1 has value [when file.php is executed
> > thru cron].

>
> From PHP manual:
>
> $_SERVER is an array containing information such as headers, paths, and
> script locations. The entries in this array are created by the webserver.
> There is no guarantee that every webserver will provide any of these;
> servers may omit some, or provide others not listed here. That said, a
> large number of these variables are accounted for in the » CGI 1.1
> specification, so you should be able to expect those.
>
> The "webserver" thing is a typo, but it's true that available variables
> differ depending on where you execute the script. I suggest you try this
> code:
>
> <?
>
> print_r($_SERVER);
>
> ?>
>
>


When I run this script from the command line or the web it does show
SCRIPT_FILENAME [with the correct value]. But when the script runs from
cron it is NULL. Is this normal behavior?

-- Mahesh
http://www.greynium.com/

Reply With Quote
  #5 (permalink)  
Old 07-25-2006
Jerry Stuckle
 
Posts: n/a
Default Re: Reading SCRIPT_FILENAME thru cron

BG Mahesh wrote:
> Alvaro G. Vicario wrote:
>
>>*** BG Mahesh escribió/wrote (24 Jul 2006 08:23:36 -0700):
>>
>>>I am using PHP 5.0.4 on OpenSuse 10.x. I have the following piece of
>>>code,
>>>
>>>$sp1 = $_SERVER["SCRIPT_FILENAME"];
>>>
>>>$sp1 is set correctly when I execute file.php thru the browser. But
>>>when I run that script thru cron [as root] $sp1 is always null.
>>>
>>>But on Redhat we see that $sp1 has value [when file.php is executed
>>>thru cron].

>>
>>From PHP manual:
>>
>>$_SERVER is an array containing information such as headers, paths, and
>>script locations. The entries in this array are created by the webserver.
>>There is no guarantee that every webserver will provide any of these;
>>servers may omit some, or provide others not listed here. That said, a
>>large number of these variables are accounted for in the » CGI 1.1
>>specification, so you should be able to expect those.
>>
>>The "webserver" thing is a typo, but it's true that available variables
>>differ depending on where you execute the script. I suggest you try this
>>code:
>>
>><?
>>
>>print_r($_SERVER);
>>
>>?>
>>
>>

>
> When I run this script from the command line or the web it does show
> SCRIPT_FILENAME [with the correct value]. But when the script runs from
> cron it is NULL. Is this normal behavior?
>
> -- Mahesh
> http://www.greynium.com/
>


Is the cron job calling the page through the web server? Or is it just
executing the script?

$_SERVER is filled in by the web server - and it won't exist if you
don't access the page though the server (http://...).


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #6 (permalink)  
Old 07-25-2006
Alvaro G. Vicario
 
Posts: n/a
Default Re: Reading SCRIPT_FILENAME thru cron

*** Jerry Stuckle escribió/wrote (Mon, 24 Jul 2006 23:16:11 -0400):
> $_SERVER is filled in by the web server - and it won't exist if you
> don't access the page though the server (http://...).


Not necessarily. I do get quite a large $_SERVER variable when running PHP
from command line. But as manual warns available values may vary.


--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Reply With Quote
  #7 (permalink)  
Old 07-27-2006
BG Mahesh
 
Posts: n/a
Default Re: Reading SCRIPT_FILENAME thru cron


> >
> > When I run this script from the command line or the web it does show
> > SCRIPT_FILENAME [with the correct value]. But when the script runs from
> > cron it is NULL. Is this normal behavior?
> >
> > -- Mahesh
> > http://www.greynium.com/
> >

>
> Is the cron job calling the page through the web server? Or is it just
> executing the script?
>
> $_SERVER is filled in by the web server - and it won't exist if you
> don't access the page though the server (http://...).
>
>


hi

I think I found the problem. On the machine where things work I have
PHP-CLI and the other one that was giving me grief had PHP-CGI.

Where does one find rpms for PHP-5.0.4-CLI [OpenSuse]?

-- Mahesh
http://www.oneindia.in/

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:37 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0