Namnath, Sharyn wrote:
I am an utter newbie when it comes to Grass but I have a very rudimentary
knowledge of running it. I have a co-worker running grass with C++, but I
can't seem to get it to work with PHP. Has anyone implemented Grass with
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
yourself.
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:
GRASS_GNUPLOT
GRASS_GUI
GRASS_PAGER
GRASS_PERL
GRASS_WISH
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@virgin.net>