Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8474065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:31:28+00:00 2026-06-10T17:31:28+00:00

I have here an myAction function in some controller. And it has one class

  • 0

I have here an myAction function in some controller. And it has one class instance:

public function myAction() {

    ...
    $myAnalyzer = new Analysis();
    $myAnalyzer->analyze();
    ...
}

Let say this function analyze() takes 10 mins. That means it blocks my.phtml 10 mins, which is unacceptable. What I want is to render my.phtml first and then to show intermediate result from analyze() on my.phtml.

function analyze() {

... 
    foreach($items as $rv) {

        ...
        ...
        // new result should be stored in db here 
    }

}

As far as I know, it’s impossible, for there is just one thread in PHP. So I decided to ajax-call from my.phtml to run myAnalyzer instance.

First question: is that right? Can I do it in myAction() without blocking?

OK, now I run myAnalyzer using some script, say worker.php, from my.phtml with the help of javascript or JQuery.

Second question: how can I know when each foreach-loop ends? In other words, how can I let worker.php send some signal (or event) to my.phtml or zend framework. I do NOT want to update my.phtml on a time basis using javascript timer. That’s all that I need to know, since intermediate data is supposed to be stored in DB.

Third question: the myAnalyzer muss stop, when user leaves pages. For that I have this code.

window.onbeforeunload = function(e) {

    // killer.php kills myAnalyzer
};

But how can javascript communicate with myAnalyzer? Is there something like process-id? I mean, when worker.php runs myAnalyzer, it registers its process-id in zend framework. And when user leave page, killer.php stops myAnalyzer using this process-id.

I appreciate the help in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:31:30+00:00Added an answer on June 10, 2026 at 5:31 pm

    First Q.: Yeah, I’m afraid that is correct.

    Second Q.: I do not understand what do you mean here. See code example below

    foreach($data => $item) {
       ...
    }
    //code here will be executed only after foreach loop is done. 
    

    Third Q.: Take a look at this page. You can set this to false (But I suppose it is already like that) and send something to client from time to time. Or you can set it to true and check if user is still connected with connection_aborted function. What I mean here is that you can run your worker.php with ajax and configure your request so browser will not disconnect it because of timeout (so connection will be kept while user stay on page). But it will be closed if user leave the page.

    EDIT:
    About second question. There are few options:

    1) you may use some shared memory (like memcached, for instance). And call server with another ajax request from time to time. So after each loop is ended – you put some value into memcached and during request you can check that value and build response/update your page based on that value

    2) There is such thing like partial response. It is possible to get some piece of response with XMLHTTPRequest, but as I remember – that is not really useful at this moment as it is not supported by many browsers. I do not have any details about this. Never tried to use it, but I know for sure that some browsers allow to process portions of response with XMLHTTPRequest.

    3) You can use invisible iframe to call your worker.php instead of XMLHTTPRequest. In this case you can send some piece of where you can put a javascript which will call some function in parrent window and that function will update your page. That is one of Long-polling COMET implementations if you want to get some more information. There are some pitfalls (for instance, you may need to ensure that you are sending some specyfic amount of symbols in response in order to get it executed in some browser), but it is still possible to use (some web browser chats are based on this).

    2) and 3) is also good because it will solve your third question problem automatically. At the same time 1) may be simpler, but it will not solve a problem in third question.

    One more thing – as you will have long running script you must remember that session may block execution of any other requests (if default file based PHP session is used – this will happen for sure)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question I have here is for some reason when the getInboxUnreadMessagesCount js function
I have here a list of items in a table. Each item has a
I am new to c# and I have this problem: I have here a
I have an action : [HttpPost] public ActionResult MyAction(MyModel model) { ... if (model.MyCondition
I have a javascript function in which I want to open a new window
I do have my own Controller in Magento, that has been done by following
I have two classes: Action and MyAction . The latter is declared as: class
I have following implementation public abstract class BaseAcion extends ActionSupport { private String result;
I have here a bubble popping game where bubbles fall from top of the
What I have here is a PHP page working with the Facebook API. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.