php asynchronous call and getting response from the background job

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kevinlu28
    New Member
    • Jul 2007
    • 2

    php asynchronous call and getting response from the background job

    Hello,

    I have done some google search on this topic and couldn't find the answer to my question.

    What I want to achieve is the following:
    1. the client make an asynchronous call to a function in the server
    2. the server runs that function in the background, and the client is not hanging in the meantime
    3. the client constantly make a call to the server requesting the status of the background job

    Can you please give me some advices on resolving my issue?

    Thank you very much! ^-^
  • dgreenhouse
    Recognized Expert Contributor
    • May 2008
    • 250

    #2
    Here's a quick first stab at some concepts...
    There are no sequence numbers, there's little supporting description, and it's a bit dense, but the general idea can be groked - I hope.

    By dgreenhouse at 2010-01-29

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      AFAIK, this is not something that PHP is capable of. AJAX can do this and your server can do this, but PHP cannot.

      Comment

      • dgreenhouse
        Recognized Expert Contributor
        • May 2008
        • 250

        #4
        I'm assuming that the frontend and backend process controllers are based on PHP. In that part of the design, PHP is more than adequate to meet the requirements.

        Comment

        • kovik
          Recognized Expert Top Contributor
          • Jun 2007
          • 1044

          #5
          PHP scripts can serve as the background process. However, PHP cannot start an asynchronous process.

          Comment

          • dgreenhouse
            Recognized Expert Contributor
            • May 2008
            • 250

            #6
            Yep... I know...

            The async starts with the Ajax on the client end and is picked up by the frontend controller. The frontend controller schedules the job or spawns a backend process immediately to handle it. The backend process (as alluded to) can be invoked via cron although the minimum interval is limited to 1 minute.

            Regardless, if this is in a shared hosting environment, there may be policies in place that terminate jobs (cli or not) running for more than x minutes. If that's the case, some type of job restart mechanism has to be designed (i.e. tracking script execution time, store temporary results, exit elegantly in prep for restart before the O.S. or other process kills the job in process.) [Of course Apache and IIS have timeout functions that might come into play depending on how the jobs are run.]

            I've got some async stuff working for inter-server process communications which is a combination of PHP, .NET, WSDL, MySQL, MSSQL, (nix) cron jobs, and (windows) task scheduler jobs.

            ~~~ On another note... ~~~

            Although this is somewhat Zend Framework specific, here's some interesting reading:
            The Mysteries Of Asynchronous Processing With PHP - Part 1:...
            The Mysteries Of Asynchronous Processing With PHP - Part 2:...
            The Mysteries Of Asynchronous Processing With PHP - Part 3:...

            Comment

            Working...