Jump to content

Run client server processes independently of server side only processing


george

Recommended Posts

When a user inputs zip code information in my web app, there is processing I do with that user input that takes some time. I do not want that time to cause a delay in the client user experience. In other words, I want that processing to occur server side only, on a time available basis, independently of the client server interactions of the application. How can I accomplish this?

Link to comment
Share on other sites

One solution may be to send a request using ajax at some point after they log in. The browser will be waiting for the response to come back, but it won't freeze anything. If they go to another page though the request might get cancelled.

Link to comment
Share on other sites

You should also be able to use exec() to spawn a background process that then runs the time-consuming script.

Link to comment
Share on other sites

JustSomeGuy - actually, I was wondering if I sent to AJAX request back to the client, does that stop the php script that was processing the request from continueing to run? Synook - I will try spawning a background process eith exec(), thanks. Thanks for the replies guys.

Link to comment
Share on other sites

No, exec() is for running an executable that is outside of the php shell. Like running a DOS or UINUX command from within a php script. Gosh, I was doing that from compiled C code back in the late 80's. Anyway, what I am looking for is closer to parallel processing, except it's not. If one php app can deal with many requests from many clients without these requests interfering with each other, then there must be a way to spawn a process independent of the client/server processing. I think this is done when a php app spawns a process on a database server. The php app can wait for a return result, or just keep on processing, while the data processing on the server continues to run independently. Running a stored procedure on a database server would be an example of this. The php app does not have to stop and wait for the DBMS stored procedure to finish. I guess I will have to create some tests to see if by a function not returning a value, will that function run independently of the program that called it?

Link to comment
Share on other sites

You can also fork a process, just like you were doing from compiled C code in the late 80's:http://www.php.net/manual/en/function.pcntl-fork.php

JustSomeGuy - actually, I was wondering if I sent to AJAX request back to the client, does that stop the php script that was processing the request from continueing to run?
The ajax request doesn't go to the client, it comes from it. The request is from the browser to the server. When the page loads after the initial PHP script you can have some Javascript on the page that sends another request to the server to run another PHP script while the page sits there.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...