PHP as an embedded scripting language

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roger

    PHP as an embedded scripting language

    ......ie in my application!

    Basically I want to add a scripting language to a cross platform
    application. The prime requirements are that it is:

    a) Small
    b) May be easily staticlly compiled into the app and require nothing
    more than libc and sockets.
    c) It must be easy to add new functions in C to hook into the app.
    d) Reasonably easy to learn and use.

    After looking at the many options available I have almost settled on
    Lua, however I would **like** to use PHP, I have used the apache PHP
    module for server side scripting in the past and like it. It has been
    excluded a bit from my choice because I could not find out anything
    **about** using it as an embedded scripting language for apps, and any
    attempt to search for e.g "PHP embedded" results in zillions of
    references to embedding in HTML etc.

    Can anybody give me any pointers or tips on this aspect/use of the
    language?

  • Jerry Stuckle

    #2
    Re: PHP as an embedded scripting language

    Roger wrote:[color=blue]
    > .....ie in my application!
    >
    > Basically I want to add a scripting language to a cross platform
    > application. The prime requirements are that it is:
    >
    > a) Small
    > b) May be easily staticlly compiled into the app and require nothing
    > more than libc and sockets.
    > c) It must be easy to add new functions in C to hook into the app.
    > d) Reasonably easy to learn and use.
    >
    > After looking at the many options available I have almost settled on
    > Lua, however I would **like** to use PHP, I have used the apache PHP
    > module for server side scripting in the past and like it. It has been
    > excluded a bit from my choice because I could not find out anything
    > **about** using it as an embedded scripting language for apps, and any
    > attempt to search for e.g "PHP embedded" results in zillions of
    > references to embedding in HTML etc.
    >
    > Can anybody give me any pointers or tips on this aspect/use of the
    > language?
    >[/color]

    PHP ia not compiled, so it won't meet your second requirement.
    Additionally, I've never seen it embedded in anything but html. While I
    see no reason why it couldn't be, it's the Apache (or IIS) PHP module
    which senses the <?php and ?> tags and passes what's between them to the
    interpreter. You'd have to create a similar module for a standalone app.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Roger

      #3
      Re: PHP as an embedded scripting language


      Jerry Stuckle wrote:
      [color=blue]
      >
      > PHP ia not compiled, so it won't meet your second requirement.[/color]

      Oops, no, I misled you there! What I meant was that I need to compile
      the interpreter into the application. The embedded interpreter would
      interpret uncompiled code.
      [color=blue]
      > Additionally, I've never seen it embedded in anything but html. While I
      > see no reason why it couldn't be, it's the Apache (or IIS) PHP module
      > which senses the <?php and ?> tags and passes what's between them to the
      > interpreter. You'd have to create a similar module for a standalone app.[/color]

      PHP can run as a stanalone interpter. In fact the CGI version is quite
      capable as being used as such (or rather **it is** a standalone
      interpreter).

      However, as you point out, it is pratically always used in web server
      scenarious, I don't no how much this has detracted from it's
      suitability as an embedded scripting engine.

      Comment

      • NC

        #4
        Re: PHP as an embedded scripting language

        Roger wrote:[color=blue]
        >
        > PHP can run as a stanalone interpter. In fact the CGI version is quite
        > capable as being used as such (or rather **it is** a standalone
        > interpreter).
        >
        > However, as you point out, it is pratically always used in web server
        > scenarious, I don't no how much this has detracted from it's
        > suitability as an embedded scripting engine.[/color]

        Well, there's also the command-line interpreter...

        Cheers,
        NC

        Comment

        • Jerry Stuckle

          #5
          Re: PHP as an embedded scripting language

          Roger wrote:[color=blue]
          > Jerry Stuckle wrote:
          >
          >[color=green]
          >>PHP ia not compiled, so it won't meet your second requirement.[/color]
          >
          >
          > Oops, no, I misled you there! What I meant was that I need to compile
          > the interpreter into the application. The embedded interpreter would
          > interpret uncompiled code.
          >
          >[color=green]
          >>Additionall y, I've never seen it embedded in anything but html. While I
          >> see no reason why it couldn't be, it's the Apache (or IIS) PHP module
          >>which senses the <?php and ?> tags and passes what's between them to the
          >>interpreter . You'd have to create a similar module for a standalone app.[/color]
          >
          >
          > PHP can run as a stanalone interpter. In fact the CGI version is quite
          > capable as being used as such (or rather **it is** a standalone
          > interpreter).
          >
          > However, as you point out, it is pratically always used in web server
          > scenarious, I don't no how much this has detracted from it's
          > suitability as an embedded scripting engine.
          >[/color]

          Roger,

          I don't know how you could compile the interpreter into your program. I
          suspect it would be quite difficult, requiring some changes to the
          interpreter code. But I guess it could be done.

          Alternatively, you could call the command line interpreter and buffer
          the contents back into your program by redirecting stdout to a pipe.

          I think it would be difficult, though. Remember - PHP itself doesn't
          have any real user interface other than a command line prompt.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Roger

            #6
            Re: PHP as an embedded scripting language


            Jerry Stuckle wrote:
            [color=blue]
            > I think it would be difficult, though. Remember - PHP itself doesn't
            > have any real user interface other than a command line prompt.
            >[/color]

            Allthougth it is not very relevant to my problem, I would point out
            that there is a PHPGTK project http://gtk.php.net/ which binds GTK
            widgets to a PHP engine, and thus **does** allow you to create stand
            alone GUI apps with PHP.

            The apps will run on any platform GTK runs on (Win, *nix, Mac ......)

            Comment

            • Mike Willbanks

              #7
              Re: PHP as an embedded scripting language

              Roger wrote:[color=blue]
              > Jerry Stuckle wrote:
              >
              >[color=green]
              >>I think it would be difficult, though. Remember - PHP itself doesn't
              >>have any real user interface other than a command line prompt.
              >>[/color]
              >
              >
              > Allthougth it is not very relevant to my problem, I would point out
              > that there is a PHPGTK project http://gtk.php.net/ which binds GTK
              > widgets to a PHP engine, and thus **does** allow you to create stand
              > alone GUI apps with PHP.
              >
              > The apps will run on any platform GTK runs on (Win, *nix, Mac ......)
              >[/color]
              I would recommend downloading the php source code and running around in
              there. It should be too hard to compile it into your own program. You
              would just need to load up the zend engine everytime you were about to
              parse some type of php document.



              --
              Mike Willbanks
              Zend Certified Engineer

              Comment

              Working...