PHP embedded as a general script language?

[email protected] ("K. Albertsen") Thu, 23 May 2002 14:07:45 +0200
Newsgroups php.evangelism
Message-ID <[email protected]>
(If this is not the right group for asking this kind of questions, please
tell me where
to go! I did not find any info directly covering my needs at the www.php.net
website,
so I figured the evangelists might convince me that PHP is The Right Choice
nevertheless...)

We are considering various alternatives for embedding a script interpreter
in a c/c++
application - *not* a web-server. Scripts is a way to customize the
application on the fly:
The user will identify a script file at startup, and at specific execution
points, the application
will call a script function with a well defined set of parameters, as if it
were another c/c++
function, and receive another well defined set of parameters as a result
value. (Actually,
scripts will be activated at several points in the execution, so each script
file will contain
multiple functions.)

The scripts will, in addition to the call parameters, access a MySql
database (which is also
accessed by the c/c++ part of the application), and should have  access to
environment
information. Scripts do not need access to network functions, and do not
need to perform
user interactions. However, performance is significant, as the script
functions will be executed
several thousand times every time the application is run. In the first
version, the application
will be run under Linux, but in the future we will probably like to use the
same scripts and
implementation techniqes for MS-Windows based calculations.

For performance reasons, I assume that embedding the interpreter into the
application
process would be significantly better than running php in a separate
process. Also, the
PHP script should be able to work within the same SQL transaction as the
c/c++ parts
of the application. (In other words, we would like the code as far as
possible to behave
externally as if  the function was written in c rather than PHP!).

Is the PHP interpreter suitable for embedding into a general application
(not a web server)
this way? Has it been (successfully) done before? If not, would it be simple
to construct an
environment for the interpreter where it "believes" that it operates in an
enviroment similar to
a web server similar to, say, Apache, so that changes to the interpreter is
minimized - or are
the ties to web server functionality so tight that this is not feasible?

I do not myself have any experience with PHP programming, but several of the
future users
of the application(s) have been using PHP for web server programming for a
long time and
have a strong preference for this language over its competitors.

I have retrieved the PHP source code, but before I start digging into it, I
would like to
know other people's opinion about the chances of success - after all,
understanding how
the code works is not a left-hand job for a Friday afternoon... :-)

I'd be grateful for all hints and advice!

Ketil Albertsen
Paradigma Project,
The Norwegian National Library