Can php be used for daemons like this?

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

    #1

    Can php be used for daemons like this?

    I have a C++ program.

    I would like it to send data to a web server.

    A script on said server would interpret this data and make some changes to
    an SQL database on the server.

    Googling I can find examples where a perl script daemon is used to
    update a database from external data and then php is used to extract the
    data to create webpages. But the only examples I can find of php being
    used for data input as opposed to retrieval is via web-page based forms.

    I tried looking in the php manual for information, but I wasn't really
    quite sure what I was looking for - I'm looking for information on which
    language I should be learning, not for information on how to do something
    in a language I already know.

    I know that I could learn perl to do what I want, but learning
    perl seems rather like overkill given my relatively simple ambitions.

    Any advice?

    Thanks,

    James
  • Phil Roberts

    #2
    Re: Can php be used for daemons like this?

    With total disregard for any kind of safety measures James Gregory
    <jamesg@f2s.com > leapt forth and uttered:
    [color=blue]
    > I have a C++ program.
    >[/color]
    <snip>

    It's possible using PHP's socket functions. Take a look at some of
    the user notes over at http://uk.php.net/manual/en/ref.sockets.php

    --
    Phil Roberts | Nobody In Particular | http://www.flatnet.net/

    Comment

    • James Gregory

      #3
      Re: Can php be used for daemons like this?

      On Tue, 10 Feb 2004 14:29:40 -0600, Phil Roberts wrote:
      [color=blue]
      > With total disregard for any kind of safety measures James Gregory
      > <jamesg@f2s.com > leapt forth and uttered:
      >[color=green]
      >> I have a C++ program.
      >>[/color]
      > <snip>
      >
      > It's possible using PHP's socket functions. Take a look at some of
      > the user notes over at http://uk.php.net/manual/en/ref.sockets.php[/color]

      OK...I guess I'll learn php rather than perl then. Perl looks messy, php
      looks like C with some extra twiddly bits.

      Thanks,

      James

      Comment

      • Pedro Graca

        #4
        Re: Can php be used for daemons like this?

        [ my apologies first ... I only think I'm not goofing ]

        James Gregory wrote:[color=blue]
        > I have a C++ program.
        >
        > I would like it to send data to a web server.[/color]

        OK. HTTP POST is probably your best bet (could be HTTP GET).

        [color=blue]
        > A script on said server would interpret this data and make some changes to
        > an SQL database on the server.[/color]

        OK. Could also be a compiled C++ (or anything else) CGI program.


        (snip)[color=blue]
        > I know that I could learn perl to do what I want, but learning
        > perl seems rather like overkill given my relatively simple ambitions.[/color]

        If you have control over the web server (and can install a CGI program),
        I think you could get away with learning CGI for C++.

        [color=blue]
        > Any advice?[/color]

        Learn PHP :-)
        --
        --= my mail box only accepts =--
        --= Content-Type: text/plain =--
        --= Size below 10001 bytes =--

        Comment

        • Chung Leong

          #5
          Re: Can php be used for daemons like this?

          PHP has a way of slowly eating up more and more memory as it runs. So using
          a PHP script as a daemon might not be a good idea. You might want to try
          PHP5. The memory management is much improved.

          Perhaps your C++ program can spawn an instance of PHP everytime you need to
          make some updates?

          Uzytkownik "James Gregory" <jamesg@f2s.com > napisal w wiadomosci
          news:pan.2004.0 2.10.19.35.43.9 51177@f2s.com.. .[color=blue]
          > I have a C++ program.
          >
          > I would like it to send data to a web server.
          >
          > A script on said server would interpret this data and make some changes to
          > an SQL database on the server.
          >
          > Googling I can find examples where a perl script daemon is used to
          > update a database from external data and then php is used to extract the
          > data to create webpages. But the only examples I can find of php being
          > used for data input as opposed to retrieval is via web-page based forms.
          >
          > I tried looking in the php manual for information, but I wasn't really
          > quite sure what I was looking for - I'm looking for information on which
          > language I should be learning, not for information on how to do something
          > in a language I already know.
          >
          > I know that I could learn perl to do what I want, but learning
          > perl seems rather like overkill given my relatively simple ambitions.
          >
          > Any advice?
          >
          > Thanks,
          >
          > James[/color]


          Comment

          • Andy Jeffries

            #6
            Re: Can php be used for daemons like this?

            James Gregory wrote:[color=blue]
            > I have a C++ program.
            >
            > I would like it to send data to a web server.
            >
            > A script on said server would interpret this data and make some changes to
            > an SQL database on the server.[/color]

            Have you written the C++ program and therefore have control over where
            it sends the data?

            If so, why can't you just have a PHP script sitting on the web server
            (as a web accesible page) that receives the data in a normal HTTP manner
            and updates the DB?

            Cheers,


            Andy

            Comment

            • James Gregory

              #7
              Re: Can php be used for daemons like this?

              On Wed, 11 Feb 2004 15:06:40 +0000, Andy Jeffries wrote:
              [color=blue]
              > Have you written the C++ program and therefore have control over where
              > it sends the data?[/color]

              Yes...
              [color=blue]
              > If so, why can't you just have a PHP script sitting on the web server
              > (as a web accesible page) that receives the data in a normal HTTP manner
              > and updates the DB?[/color]

              Well, I don't know, as I don't fully understand how all this CGI
              stuff works right now - as I fully admit, I'm not really sure what I'm
              talking about yet.

              When you hit the "Send" button on an html form, I'm still not quite sure
              what it does, as all the tutorials I can find sort of say "when you
              click send <some magic stuff happens>, and then your
              cgi program named in the html form is run".

              There are tutorials and free libraries for CGI and C++ and php and such
              like everywhere, but they are all about how to deal with the input of html
              forms, rather than what http post actually means.

              Does http post/get simply send a packet to the server with headers to the
              effect of "Please run CGI program x.cgi and return the output to my IP x"?
              So it would be possible to write a program that could automatically fill
              in anyone's web form, anywhere?

              If this were the case, then I see what you mean, all I would need to do
              would be to work out what the right headers look like.

              If this isn't the case, I don't understand what you mean.

              James

              Comment

              • Pedro Graca

                #8
                Re: Can php be used for daemons like this?

                James Gregory wrote:[color=blue]
                > Does http post/get simply send a packet to the server with headers to the
                > effect of "Please run CGI program x.cgi and return the output to my IP x"?
                > So it would be possible to write a program that could automatically fill
                > in anyone's web form, anywhere?[/color]

                You're right!

                [color=blue]
                > If this were the case, then I see what you mean, all I would need to do
                > would be to work out what the right headers look like.[/color]

                I don't know the exact details about the HTTP protocol
                ( see http://www.w3.org/Protocols/rfc2616/rfc2616.html )
                but a POST request, in terms of what the client sends to
                the server looks like (I never tried it, though):


                POST http://www.example.com/path/to/program HTTP/1.0
                User-Agent: My C++ Application/0.97.1 beta
                Cookie: id=76a53fd5027c 000
                Content-Type: application/x-www-form-urlencoded
                Content-Length: 28

                name=Pedro+Grac a


                After that, on the server side, I have no idea how the program
                "path/to/program" receives the "name=Pedro+Gra ca"


                You might try a GET with telnet, to get a feeling for how it works :)
                Start telnet
                ] telnet www.example.com 80
                wait for the server to tell you it's ready (Escape character is '^]'.)
                Type the GET and two ENTERs
                ] GET / HTTP/1.0
                ]
                Your Request is successful (hopefully)


                you might try to send a few more details along with the page you want:
                ] GET / HTTP/1.0
                ] Cookie: test=true
                ] X-perimenting: true
                ]

                --
                --= my mail box only accepts =--
                --= Content-Type: text/plain =--
                --= Size below 10001 bytes =--

                Comment

                • James Gregory

                  #9
                  Re: Can php be used for daemons like this?

                  On Wed, 11 Feb 2004 22:52:16 +0000, Pedro Graca wrote:

                  <snip>

                  OK, thanks for all that. I guess I'll just play about with the stuff from
                  the RFC and see what makes it work.

                  James

                  Comment

                  Working...