472,811 Members | 1,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 software developers and data experts.

Can PHP be dynamically loaded and called from a C program?

I anticipate wanting PHP to evaluate a lot of expressions and would
rather not create subprocesses to do it from inside my C program.

I've googled around for calling PHP from C, and know Apache does it, but
my C program won't have a full Apache environment. Can the libphp.so be
used otherwise?
Jul 17 '05 #1
7 2547
NC
Thomas Gagne wrote:

I anticipate wanting PHP to evaluate a lot of expressions and would
rather not create subprocesses to do it from inside my C program.

I've googled around for calling PHP from C, and know Apache does it,
but my C program won't have a full Apache environment. Can the
libphp.so be used otherwise?


No, but there is a command-line PHP interpreter that you can
use without Apache or any HTTP server whatsoever.

Cheers,
NC

Jul 17 '05 #2
On Tue, 29 Mar 2005 10:25:20 -0500, Thomas Gagne <tg****@wide-open-west.com>
wrote:
I anticipate wanting PHP to evaluate a lot of expressions and would
rather not create subprocesses to do it from inside my C program.

I've googled around for calling PHP from C, and know Apache does it, but
my C program won't have a full Apache environment. Can the libphp.so be
used otherwise?


Looks like it's possible; although a bit tricky to search for, since most hits
for "embedding php" come up with embedding PHP in HTML in a webserver-parsed
page.

The trail seems to start here:
http://www.zend.com/lists/php-dev/200209/msg01063.html

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3

"Thomas Gagne" <tg****@wide-open-west.com> wrote in message
news:OY********************@wideopenwest.com...
I anticipate wanting PHP to evaluate a lot of expressions and would
rather not create subprocesses to do it from inside my C program.

I've googled around for calling PHP from C, and know Apache does it, but
my C program won't have a full Apache environment. Can the libphp.so be
used otherwise?


You will never be able to use libphp.so without building Apache into your C
program. The PHP module calls a number of functions within Apache. Unless
you implement your own version of these, the dynamic library will not even
load.

Writing a PHP module that encapsute your C code is the better approach.
Jul 17 '05 #4
NC wrote:
Thomas Gagne wrote:

I anticipate wanting PHP to evaluate a lot of expressions and would
rather not create subprocesses to do it from inside my C program.

I've googled around for calling PHP from C, and know Apache does it,
but my C program won't have a full Apache environment. Can the
libphp.so be used otherwise?


No, but there is a command-line PHP interpreter that you can
use without Apache or any HTTP server whatsoever.


Is there a reason why you (OP) specificaly want to embed PHP? If all you
need is an embedded scripting language, both TCL and python have a long
pedigree in this department.

HTH

C.
Jul 17 '05 #5
On Wed, 30 Mar 2005 02:43:18 -0500, "Chung Leong" <ch***********@hotmail.com>
wrote:
"Thomas Gagne" <tg****@wide-open-west.com> wrote in message
news:OY********************@wideopenwest.com...
I anticipate wanting PHP to evaluate a lot of expressions and would
rather not create subprocesses to do it from inside my C program.

I've googled around for calling PHP from C, and know Apache does it, but
my C program won't have a full Apache environment. Can the libphp.so be
used otherwise?


You will never be able to use libphp.so without building Apache into your C
program. The PHP module calls a number of functions within Apache. Unless
you implement your own version of these, the dynamic library will not even
load.


That's exactly what the embed SAPI is for. Clearly it's possible to load PHP
into an executable without Apache being involved at all - else running PHP
under IIS would be impossible.

The embed SAPI, from the looks of it, fills all the gaps usually provided by a
webserver's API, allowing PHP to be called from arbitrary C programs.

It's woefully underdocumented and from a few minutes playing with it I've not
got it to actually link properly yet, but the principle looks sound.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #6
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:l7********************************@4ax.com...
On Wed, 30 Mar 2005 02:43:18 -0500, "Chung Leong" <ch***********@hotmail.com> wrote:
"Thomas Gagne" <tg****@wide-open-west.com> wrote in message
news:OY********************@wideopenwest.com...
I anticipate wanting PHP to evaluate a lot of expressions and would
rather not create subprocesses to do it from inside my C program.

I've googled around for calling PHP from C, and know Apache does it, but my C program won't have a full Apache environment. Can the libphp.so be used otherwise?
You will never be able to use libphp.so without building Apache into your Cprogram. The PHP module calls a number of functions within Apache. Unless
you implement your own version of these, the dynamic library will not evenload.


That's exactly what the embed SAPI is for. Clearly it's possible to load

PHP into an executable without Apache being involved at all - else running PHP
under IIS would be impossible.

The embed SAPI, from the looks of it, fills all the gaps usually provided by a webserver's API, allowing PHP to be called from arbitrary C programs.

It's woefully underdocumented and from a few minutes playing with it I've not got it to actually link properly yet, but the principle looks sound.


IIRC, libphp.so is the name of the mod_php binary. I could be wrong though.
Jul 17 '05 #7
Colin McKinnon wrote:
NC wrote:

Thomas Gagne wrote:
I anticipate wanting PHP to evaluate a lot of expressions and would
rather not create subprocesses to do it from inside my C program.

I've googled around for calling PHP from C, and know Apache does it,
but my C program won't have a full Apache environment. Can the
libphp.so be used otherwise?


No, but there is a command-line PHP interpreter that you can
use without Apache or any HTTP server whatsoever.

Is there a reason why you (OP) specificaly want to embed PHP? If all you
need is an embedded scripting language, both TCL and python have a long
pedigree in this department.

I've a business-rule engine written in Smalltalk that exists in such a
way that any language could be used to describe a rule. Because we've
PHP programmers on-staff I thought PHP would be a valuable extension.
Since Smalltalk can call C library functions I thought that might be one
way to talk to PHP. So in essence, calling C from inside PHP doesn't
work because I want to get into PHP from the outside.

Thanks for the reminders on Python and TCL. With both being open-source
I could theoretically load these and allow access to Smalltalk objects
from within them. That would be especially cool for Python.
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: cjl | last post by:
Hey all: I've searched the newsgroup, and googled, but I'm stuck. I want to be able to 'dynamically' add a .js file to a web page after the page has loaded, based on user interaction. For...
1
by: Benjamin | last post by:
Hi, I'm currently writing a Web Services that interacts with a database. To allow me to use not just one database provider (for example, I could use MS Access, SQL Server or MySQL), the Web...
1
by: Greg | last post by:
In my ASP.NET application I have a button that when pressed, data needs to be saved based on what the user typed in. I have other controls on the same page that should be updated as a result of the...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
0
by: Matt Howeson | last post by:
I have a problem with a usercontrol that is dynamically loaded, from a web control and is not restoring it's viewstate properly. Here's the scenario. Within our content management system, I have...
3
by: supvine | last post by:
Hello, I am developing a page that has several custom web user controls that need to be loaded dynamically. Some of the controls are loaded based on the action (button-click) of a different...
12
by: Steve_Black | last post by:
I posted a similar message earlier but we've geared away from the original topic somewhat so I thought I'd post again in hopes of getting input from others. I am creating a MenuStrip...
2
by: A.Wussow | last post by:
Hi Everybody, i want to load dynamically content from some user controls (with forms, or some data-controls) using atlas. So i use an UpdatePanel for loading the user control into a placeholder....
7
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.