Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- how to tell CLI or webserver execution?
October 24, 2008, 3:29 pm
rate this thread
webserver, or by the cli?
I have some pages that I developed to be served, but now we want to
run some of them as cron jobs. I have to change some of the path
references ( our cron job scripts reference include files in the
webserver directory, and relative paths in the include files break
when they are called by a script in another directory ), and to make
everything more interoperable, I need to reference things based on
whether it's being called by Apache or by the cli. Specifically, I'm
making a reference to $_SERVER['DOCUMENT_ROOT'], which is empty when
called by the cli.
So, I need to know if the script is being called by apache or the
command line, so I can choose how to references certain included
files. How should I do this?
Re: how to tell CLI or webserver execution?
Thanks, Jerry. I just wasn't sure if certain variables were more
reliable than others. I suppose SERVER_ADDR couldn't exist in the cli;
assuming it means "web sever address".
I just checked out the php manual, and it says: 'SERVER_ADDR' The IP
address of the server under which the current script is executing ...
which doesn't necessarily rule out an ip address for the server when
called from cli... :P
- » sticky form with dynamically generated form element?
- — Next thread in » PHP Scripting Forum