Forum Moderators: coopster

Message Too Old, No Replies

php process updating and ajax

php parallel process query

         

phazei

6:18 am on Feb 6, 2009 (gmt 0)

10+ Year Member



I'm setting up a system where a user uploads a file, the file is processed, lots of php/mysql stuff is done, then a new file is made for download.

This is all being done on a single page without any reloading using ajax.

Some files are big so could take a while to process.

I'm not quite sure the best way to go about it.

Right now I'm using an ajax to first upload the file, when it's done it responds with a confirmation and the file location. That is then sent to another ajax call which goes to another page to tell it to start processing. But that would take a while to finish before sending a response that it is done.

I'd like to do it in a more straight forward manner. When the server gets the file, instead of having to output back right away, it will just go ahead and start processing the file and doing the mysql stuff, and when it's done, then respond back. But then the user is just sitting there waiting.

So, I have an idea of how to take care of that, but I have no idea if it would work. I guess I just don't know enough about how classes and variables interact with each other in separate processes. I don't even know what it would be called to google it.

So this is my idea:

class doStuff() {
public $status;
public $count;

function doing() {
/*..stuff 1..*/
$this->status = "stuff 1 done";
/*..stuff 2..*/
$this->status = "stuff 2 done";
/*..stuff 3..*/
$this->status = "stuff 3 done";
}
function status() {
return $this->status;
}

}

I have a first ajax function upload the file and start doing(). Then I have a second ajax function setup on an interval that calls status().

Will that work?

Thanks.

coopster

2:40 pm on Feb 11, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



As long as you are using asynchronous calls, yes. However, be certain you are using different instances of the request object, which means you must be certain you have your JavaScript code correct.