Comm. between Python and PHP

  • Thread starter Nils Emil P. Larsen
  • Start date
N

Nils Emil P. Larsen

Hello

I'm building a daemon in Python. It will measure and control some
physical devices on a serial bus. Since it is a daemon, it will never
terminate and I can't interfere with the regulation of the devices by
using command line parameters. I want to control the regulation by
using a Internet browser.

What is the easiest way to make my threaded Python daemon communicate
with a PHP-script running from Apache2 on localhost?

Thank you so far!

Nils Emil P. Larsen
 
P

Peter Hansen

Nils said:
I'm building a daemon in Python. It will measure and control some
physical devices on a serial bus. Since it is a daemon, it will never
terminate and I can't interfere with the regulation of the devices by
using command line parameters. I want to control the regulation by
using a Internet browser.

What is the easiest way to make my threaded Python daemon communicate
with a PHP-script running from Apache2 on localhost?

"Easiest" of course depends on lots of things, and mostly on
specifics that you haven't told us, and your personal preference.

Two obvious possibilities that come to mind are "write a file
somewhere from PHP and poll for updates from Python", and
"use sockets (TCP)" or "use UDP".

Maybe if you can describe more about what you need (e.g. what
form will this "control" take?) some even simpler suggestions
will come to mind.

-Peter
 
N

Noah

It wasn't quite clear, but I assume that you want a PHP script that
can call on the Python daemon and not have the daemon make
calls to a PHP script.

You could use xml-rpc which is built into Python as of version 2.2:
http://docs.python.org/lib/module-xmlrpclib.html
On the PHP side xmlrpc is still experimental. You have to
enable this when you build PHP:
http://us3.php.net/manual/en/ref.xmlrpc.php

You could also just add a simple HTTP interface to your daemon.
It's pretty easy to add an HTTP interface to your daemon.
Look at SimpleHTTPServer the docs:
http://docs.python.org/lib/module-SimpleHTTPServer.html
You will also need to read the source for SimpleHTTPServer.py to
figure out how it works (I don't know why they don't just put the
example
in the docs instead of putting the example in the source).

Yours,
Noah
 
N

Nick Craig-Wood

Peter Hansen said:
"Easiest" of course depends on lots of things, and mostly on
specifics that you haven't told us, and your personal preference.

Two obvious possibilities that come to mind are "write a file
somewhere from PHP and poll for updates from Python", and
"use sockets (TCP)" or "use UDP".

If the data you want to pass is structured then you might consider
XML-RPC which is a cross platform way of passing structured data
around. XML-RPC is part of the python standard library
(SimpleXMLRPCServer and xmlrpclib) and there seem to be several
implementations for PHP

http://www.google.co.uk/search?q=xml+rpc+php

That might be overkill for what you want though!
 
T

Tim Roberts

Nils Emil P. Larsen said:
Hello

I'm building a daemon in Python. It will measure and control some
physical devices on a serial bus. Since it is a daemon, it will never
terminate and I can't interfere with the regulation of the devices by
using command line parameters. I want to control the regulation by
using a Internet browser.

What is the easiest way to make my threaded Python daemon communicate
with a PHP-script running from Apache2 on localhost?

Python is perfectly capable of generating HTML. You don't have to demean
yourself by working in PHP.

Sockets and pipe files are common methods of communicating with a daemon.
 
N

Nils Emil P. Larsen

Hello
Python is perfectly capable of generating HTML. You don't have to demean
yourself by working in PHP.

Thanks for the tip about using Python instead of PHP to generate web
pages. I may follow it.

Nils Emil
 
N

Nils Emil P. Larsen

Hello

Sorry for not being too exact in my request!
If the data you want to pass is structured then you might consider
XML-RPC which is a cross platform way of passing structured data

XML-RPC looks like something very suitable for my needs. It seems
Python handles the remote procedure calls very easily (almost like
local functions).
It also works quite well in PHP. I didn't recompile anything but
downloaded Keith Devens XML-RPC Library (500 lines code). With this I
can call RPC-functions almost as easily as with Python. It took me
just about an hour to get it working...

Thanks everybody!

Nils Emil P. Larsen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top