473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Jul 24 '06 #1
6 1873
*** 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
--
Jul 24 '06 #2
*** 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
--
Jul 24 '06 #3

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/

Jul 25 '06 #4
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.
js*******@attglobal.net
==================
Jul 25 '06 #5
*** 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
--
Jul 25 '06 #6

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/

Jul 27 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mr_burns | last post by:
Hi, I am using $HTTP_SERVER_VARS to get the name of the current web page. How do I also get the GET variables using PHP as a complete string. For example: '?first=12&second=value&third=2.99'...
6
by: sherryonline | last post by:
i have a page and i need that page to be called every day at 12:00 that page is going to connect to the database fetch some emails and will start mailing them how i am goning to do this.
4
by: vagrantbrad | last post by:
I'm using python 2.4 running on Fedora Core 4. I have written a python program called ipscan.py that checks the external ip address of my cable internet connection, and on change, will update the...
3
by: the.natalie | last post by:
Hi. I am a newbie to mysql, cron, and shell scripting, so please bear with me. I have a script that is used for updating an image directory based on contents in a database. The script does the...
2
by: Robert | last post by:
I'm getting the dreaded "No input file specified" when I try to invoke PHP from thttpd (nochroot). I wrote a C program to dump environment variables before trying to invoke PHP. I've included...
4
by: Phil | last post by:
I have a php script that queries some Oracle DB and outputs a single line of plain text with <brat the end for each query. This is Apache2, php4.4.8 and Oracle Instant Client 10.1.0.5 all on CentOS...
4
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment...
0
by: Cameron Simpson | last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote: Because $HOSTNAME is a bash specific variable, set by bash but NOT EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses...
1
by: Karthik Gurusamy | last post by:
Hi, I'm working on a cron like functionality for my application. The outer loops runs continuously waking every x seconds (say x=180, 300, ..). It needs to know what events in cron has expired...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.