473,779 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2582
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.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3

"Thomas Gagne" <tg****@wide-open-west.com> wrote in message
news:OY******** ************@wi deopenwest.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******* *************@w ideopenwest.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.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #6
"Andy Hassall" <an**@andyh.co. uk> wrote in message
news:l7******** *************** *********@4ax.c om...
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******* *************@w ideopenwest.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
5066
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 example, the user make a choice by clicking on an item called 20050928, and as a result a file named "20050928/case.js" is "included", and the data contained within is available.
1
5022
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 Service dynamically loads up an assembly that implements an Interface I called IDatabase. To load the assembly and create an object, I wrote this function: private IDatabase LoadDatabasePlugin( string assemblyFile, string
1
1667
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 save, which are all dynamically created in the code behind and have event handlers registered. In the page life cycle, event handlers are called after the page is loaded. The problem is, the save is done after the controls are loaded, so the...
4
3119
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 UserControls into the PlaceHolder's child control collection depending upon which of the three radio buttons is selected. Each of the three UserControls have postback events themselves triggered by button clicks. The problem I'm having is keeping track of...
0
1536
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 a webcontrol which allows a admin user to select a usercontrol to include within a page when in "edit mode". When a user is editing the page they see a dropdown list of available controls and select one and save the page, kind of irrelevant to...
3
1187
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 control in the parent page. Currently what I have to do to make this work is set a session variable to load/unload a particular control and do a Server.Transfer to the page itself from the Button_Click event. Is this a good way of loading controls...
12
3176
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 dynamically. For each ToolStripMenuItem, I'm adding an event handler so that the same routine gets called regardless of which menu item was clicked. All of this works great - my menu is being loaded properly and my routine gets called properly. Within...
2
1802
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. Using buttons for loading new content works fine. But i still want to use a function which is callable per javascript. I think this way is more flexable than using the Buttons, becaus every button needs it's own Sub-Routine. But i want to have...
7
2152
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 CType(Me.FindControl("admin" & CStr(section("buttontext")).Replace(" ", "")), adminsection2).RefreshSection() Next End Sub
0
9633
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10137
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.