Execute php page automatically in the background ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tanyali
    New Member
    • Feb 2007
    • 43

    Execute php page automatically in the background ?

    Hi guys,

    I wanna to execute a php page automatically in the background,

    or execute it in shell script, and set this script to execute as a cron job.

    so who knows either of the two questions :
    1- execute a php page automatically in the background ?
    2- execute a php page in shell script ?

    anyone knows how to do this ?

    thanks a million.

    Tanya
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Tanya.

    I'm pretty sure this will work:
    [code=php]
    `php /path/to/file &`;

    // Alternatively, try this:
    pclose(popen('p hp /path/to/file &'));
    [/code]

    The '&' is important. It tells the shell not to wait for the process to exit.

    Comment

    • tanyali
      New Member
      • Feb 2007
      • 43

      #3
      Originally posted by pbmods
      Heya, Tanya.

      I'm pretty sure this will work:
      [code=php]
      `php /path/to/file &`;

      // Alternatively, try this:
      pclose(popen('p hp /path/to/file &'));
      [/code]

      The '&' is important. It tells the shell not to wait for the process to exit.
      thanks for answering first!

      I tried :
      `php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &` ;
      it returned :
      php: command not found
      I am wondering do I need to set up any config files in order to make shell recognize php command ?


      also tried this :
      pclose(popen('p hp /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &'));
      it returned:
      ./php.sh: line 11: syntax error near unexpected token `popen'
      ./php.sh: line 11: `pclose(popen(' php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &'));'
      I have no idea about this one.


      looking forward to your reply.
      thanks
      Tanya

      Comment

      • icenemesis
        New Member
        • Jul 2007
        • 13

        #4
        You could use AJAX to execute a php page through HTTP Request Object. I don't have any reference code right now, but if you look into that it should be what you need.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Tanya.

          Originally posted by tanyali
          I tried :
          `php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &` ;
          it returned :
          php: command not found
          I am wondering do I need to set up any config files in order to make shell recognize php command ?
          You may need to use the absolute path to the php tool. Try /usr/bin/php, /bin/php or /usr/local/bin/php. If none of these work, then there is a good chance that the PHP command-line tool is not installed on your server.

          If you want to run this command from a shell script, you don't need to use the backticks.

          Originally posted by tanyali
          also tried this :
          pclose(popen('p hp /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &'));
          it returned:
          ./php.sh: line 11: syntax error near unexpected token `popen'
          ./php.sh: line 11: `pclose(popen(' php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &'));'
          I have no idea about this one.
          This code is designed to be run from a PHP file. popen() and pclose() are PHP functions. However, you may still get the 'php not found' error as above.

          Comment

          • tanyali
            New Member
            • Feb 2007
            • 43

            #6
            heya, pbmods.

            yes, I want to run this command from a shell script.

            I tried :
            pclose(popen(ph p /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &));
            and it returned:
            ./test.sh: line 9: syntax error near unexpected token `popen'
            ./test.sh: line 9: `pclose(popen(p hp /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &));'

            and also the first method, none of that three exists.
            well, how can I install the PHP command-line tool on my server ?
            I am using apache2

            thanks ,
            Tanya

            Originally posted by pbmods
            Heya, Tanya.



            You may need to use the absolute path to the php tool. Try /usr/bin/php, /bin/php or /usr/local/bin/php. If none of these work, then there is a good chance that the PHP command-line tool is not installed on your server.

            If you want to run this command from a shell script, you don't need to use the backticks.



            This code is designed to be run from a PHP file. popen() and pclose() are PHP functions. However, you may still get the 'php not found' error as above.

            Comment

            • tanyali
              New Member
              • Feb 2007
              • 43

              #7
              Heya, Pbmods,

              it worked,

              I checked the php was installed in the dir : /usr/bin/ and what I am using is php5 instead of php, so I used the code ( bash ) :

              `/usr/bin/php5 /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &`

              and it worked !

              thanks a million !!! Pbmods
              Tanya

              Originally posted by pbmods
              Heya, Tanya.



              You may need to use the absolute path to the php tool. Try /usr/bin/php, /bin/php or /usr/local/bin/php. If none of these work, then there is a good chance that the PHP command-line tool is not installed on your server.

              If you want to run this command from a shell script, you don't need to use the backticks.



              This code is designed to be run from a PHP file. popen() and pclose() are PHP functions. However, you may still get the 'php not found' error as above.

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Heya, Tanya.

                Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)

                Comment

                Working...