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@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: IP addresses and JS.
    ... >>A computer language is just that, ... Javascript is just a programming language, and may be used to script all ... The interaction between a web browser and a server is through HTTP. ... execute scripts and/or programs, ...
    (comp.lang.javascript)
  • Limit crons process time, etc.
    ... I have a Linux Redhat 7.2 server with users and need to keep the ... mem, cpu, process time, number of processes for web server and shell ... load issues via cron. ... but a form bomb script or something could still ruin my ...
    (comp.os.linux.security)
  • Re: Help with a socket script execution
    ... necessary execute the socket server script from the console (#!/usr/ ... along with some PHP magic so the script doesn't die when the HTTP ... you give me a few details about how to use exec command? ... only execute something and finish it execution or wait until the ...
    (comp.lang.php)
  • Re: is it possible to call vbs file with js?
    ... Server side code will *never* execute in the browser. ... shared between server and client (e.g. parsers, validators, HTML forms ... But they won't share the same script block. ...
    (comp.lang.javascript)
  • Re: changing crons From: address in emails
    ... They all say they are from the "Cron Daemon". ... know more clearly which server the cron output is from. ... Then everything you print out in the script will be captured as the body ... Why not just echo `hostname` as the first line of every script? ...
    (freebsd-questions)