[GRASS5] Grass with PHP (newbie question)
NamnatSR at NV.DOE.GOV
Mon Aug 16 18:18:01 EDT 2004
Glynn (or anyone else),
Thanks for your reply. Yes, I do mean running GRASS programs from a PHP
script via "system" calls. I've been playing with setting the environment
variables, but it still doesn't work. I tried doing a simple version call
and piping it into a file. The file gets created, but there is nothing
inside of it. It just creates a zero-length file.
Here is the code I'm using :
system("env > /Users/administrator/Sites/click/environment_vars.txt");
The environment variables are echoed to the environment_vars.txt file just
> -----Original Message-----
> From: Glynn Clements [mailto:glynn.clements at virgin.net]
> Sent: Wednesday, August 11, 2004 12:19 PM
> To: Namnath, Sharyn
> Cc: Grass5 list (grass5 at grass.itc.it)
> Subject: Re: [GRASS5] Grass with PHP (newbie question)
> Namnath, Sharyn wrote:
> > I am an utter newbie when it comes to Grass but I have a very
> > knowledge of running it. I have a co-worker running grass with C++, but
> > can't seem to get it to work with PHP. Has anyone implemented Grass
> > PHP and are there any tips & tricks that anyone can give me?
> What exactly do you mean by "get it to work with PHP"? Are you talking
> about running GRASS programs from a PHP script with e.g. "system"?
> If so, you need to bear in mind that, in order to function, GRASS
> programs require a number of environment variables to be set.
> Normally, these are set by the etc/Init.sh script before it spawns the
> session shell. However, if you are trying to execute GRASS programs
> outside of a GRASS session, you will have to set the variables
> In particular, $GISBASE needs to be the path to the root of the GRASS
> installation (e.g. /usr/local/grass5), and $GISRC needs to be the name
> of the GRASS session file (5.0 uses $HOME/.grassrc5, 5.3 uses
> $HOME/.grassrc53, while 5.7 creates a new session file each time, to
> allow for multiple sessions). Also, $GISLOCK is set to the PID of the
> process which is running the Init.sh script although, AFAICT, this is
> only actually used by v.digit etc for locking the digitiser device, so
> it probably isn't relevant to a non-interactive session.
> The following variables are also set by Init.sh, but are less
> important than $GISBASE and $GISRC:
> Additionally, $PATH and $LD_LIBRARY_PATH have additional directories
> added to them.
> Apart from the issue of environment variables, you also need a mapset
> directory. This must be owned by the UID under which the GRASS
> programs are running; simply having write permission isn't sufficient.
> No locking is performed, so you cannot have multiple processes using a
> single mapset directory concurrently; each session requires its own
> mapset directory.
> In summary: if you want to run GRASS programs other than from the
> shell which is spawned by running the "grass5" script, you will need
> to duplicate much of the setup process. Read the etc/Init.sh script
> for details.
> Glynn Clements <glynn.clements at virgin.net>
More information about the grass-dev