How can i make a php program run like a service in the server?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kvijayhari
    New Member
    • Jul 2007
    • 24

    How can i make a php program run like a service in the server?

    hi

    I'm going to write a program that should be running all the time (24/7) in my server say like a service..

    Whenever my server is running this program should be running and whenever i start/restart my machine the program should automatically start and run.

    The program will be in php. How can i make this to run like a service?

    So how can do this ?
  • Stang02GT
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Moving to PHP forum in hopes they will be able to guide you better

    Comment

    • coolsti
      Contributor
      • Mar 2008
      • 310

      #3
      What do you mean by "running all the time"? That is going to chew up a lot of your CPU if you have a PHP script always doing something.

      It sounds to me like you wish a PHP script to run repeatedly, say for example every minute or every 5 minutes or every 10 minutes, or once each hour or something like that. Is that what you want? If so, you can configure your PHP script to run in a standalone fashion (without a web server, or the PHP-CLI mode) and then set up a batch program to run your script at the regular intervals you desire. If you are working on a Linux machine, you would do this by setting up a cron job. Not sure what you do if you are using Windows.

      Comment

      • kvijayhari
        New Member
        • Jul 2007
        • 24

        #4
        i'm going to use linux and i want that program to run all the like a service...

        I'm sure about that, this program should be running all the time,this program has very important monitoring and queuing stuff. so it need to be running..

        I thought of cron, but for example if the crontab itself fails, who will initiate that program.

        Actually i want that program to be running like a service whenever the server is running... it can be very nice if is automatically started when the server is started/restarted.

        Hoping for a solution

        Comment

        • dlite922
          Recognized Expert Top Contributor
          • Dec 2007
          • 1586

          #5
          curious,

          what does the program do? does it listen on a port? does it check a file or db.table for something?




          -Dan

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            PHP is mainly used for web development (though not limited to). Is your program going to be a web application? Starting programs automatically when the computer boots is the easier part that. Let's first get some information on the nature of the program first.

            Comment

            • kvijayhari
              New Member
              • Jul 2007
              • 24

              #7
              Yes, it an web application , gets data from the db and then process and it runs on my machine (server), the db gets updated thru my website..

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by kvijayhari
                Yes, it an web application , gets data from the db and then process and it runs on my machine (server), the db gets updated thru my website..
                So all you want is that the website should be available everytime the computer is switched on?

                Comment

                • kvijayhari
                  New Member
                  • Jul 2007
                  • 24

                  #9
                  Originally posted by r035198x
                  So all you want is that the website should be available everytime the computer is switched on?
                  Exactly that is i want!!

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by kvijayhari
                    Exactly that is i want!!
                    If you are using Apache with your PHP then all you need to do make sure your Apache starts automatically. There are many ways of doing this depending on your distro as well. Just google for the various options and pick the one you prefer.

                    Comment

                    • kvijayhari
                      New Member
                      • Jul 2007
                      • 24

                      #11
                      Originally posted by r035198x
                      If you are using Apache with your PHP then all you need to do make sure your Apache starts automatically. There are many ways of doing this depending on your distro as well. Just google for the various options and pick the one you prefer.
                      Thanks for your effort. But this is something different from i want..

                      I may not be clear in specifying what i want.

                      I have a website and it should run 24X7 (for this what you gave is a perfect solutions. Thanks.)

                      In the website , itself, i'm having a program may be an API, that has to be run indepedent of the status of the website. (i.e the specific program need not to use http connections and it has nothing to do on the client side.)

                      That specific API should be running on the server all the time (something like firewall..)

                      Can i write a program and make them running..?

                      I think it may be somewhat clear now.

                      Thanks again

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Then you create the PHP script as specified in post #3 and start it on machine boot using the same method that you would auto start Apache.

                        Comment

                        • kvijayhari
                          New Member
                          • Jul 2007
                          • 24

                          #13
                          Thanks guys.

                          I read that post but didn't analyzed more about that.

                          Thanks i'll move in that direction.

                          Comment

                          • olddocks
                            New Member
                            • Nov 2007
                            • 26

                            #14
                            Originally posted by kvijayhari
                            Thanks guys.

                            I read that post but didn't analyzed more about that.

                            Thanks i'll move in that direction.
                            just place the script in CRON job.

                            Comment

                            Working...