Comm. between Python and PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nils Emil P. Larsen

    #1

    Comm. between Python and PHP

    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
    --
    My reply-address is valid. www.bios-flash.dk
    Min svar-adresse er gyldig. Redning af døde BIOS'er
  • Peter Hansen

    #2
    Re: Comm. between Python and PHP

    Nils Emil P. Larsen wrote:[color=blue]
    > 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?[/color]

    "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

    Comment

    • Noah

      #3
      Re: Comm. between Python and PHP

      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:
      Source code: Lib/xmlrpc/client.py XML-RPC is a Remote Procedure Call method that uses XML passed via HTTP(S) as a transport. With it, a client can call methods with parameters on a remote server (t...

      On the PHP side xmlrpc is still experimental. You have to
      enable this when you build 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 SimpleHTTPServe r the docs:

      You will also need to read the source for SimpleHTTPServe r.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

      Comment

      • Nick Craig-Wood

        #4
        Re: Comm. between Python and PHP

        Peter Hansen <peter@engcorp. com> wrote:[color=blue]
        > Nils Emil P. Larsen wrote:[color=green]
        > > What is the easiest way to make my threaded Python daemon communicate
        > > with a PHP-script running from Apache2 on localhost?[/color]
        >
        > "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".[/color]

        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
        (SimpleXMLRPCSe rver and xmlrpclib) and there seem to be several
        implementations for PHP



        That might be overkill for what you want though!
        --
        Nick Craig-Wood <nick@craig-wood.com> -- http://www.craig-wood.com/nick

        Comment

        • Tim Roberts

          #5
          Re: Comm. between Python and PHP

          Nils Emil P. Larsen <ne-nospam7@post.cy bercity.dk> wrote:[color=blue]
          >
          >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?[/color]

          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.
          --
          - Tim Roberts, timr@probo.com
          Providenza & Boekelheide, Inc.

          Comment

          • Nils Emil P. Larsen

            #6
            Re: Comm. between Python and PHP

            Hello
            [color=blue]
            >Python is perfectly capable of generating HTML. You don't have to demean
            >yourself by working in PHP.[/color]

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

            Nils Emil
            --
            My reply-address is valid. www.bios-flash.dk
            Min svar-adresse er gyldig. Redning af døde BIOS'er

            Comment

            • Nils Emil P. Larsen

              #7
              Re: Comm. between Python and PHP

              Hello

              Sorry for not being too exact in my request!
              [color=blue]
              >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[/color]

              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


              --
              My reply-address is valid. www.bios-flash.dk
              Min svar-adresse er gyldig. Redning af døde BIOS'er

              Comment

              Working...