The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

ajax call freezes the page

I am writing up a page to collect user input, and then generate an excel file.
The generation of the excel file is slow (more than 30 sec), so I decide to separate the input stage and file creation stage.

What I do is, collect user input, save to mysql, and pass a url (to the page of excel file creation) to javascript. Javascript will be triggered by setTimeout and run ajax to call the url after 2-3 seconds. This is the page structure of how I do it:

The problem is, when the ajax is called, I cannot navigate around the pages (in the iframe of index.php). There is no error, but seems to be "loading". I have tried to use the same browser window to access the same site on the server, and also other sites on the Internet, to make sure the server is not busy to respond or the network is fully occupied.

I have tried once again, not to use ajax but instead, an iframe. The same problem exists.

I am accessing the page with a LAN IP. When I copy the IP and paste onto the browser, the site seems to be loading long, until the loading progress is done on the original tab. Does it mean the server is busy? Do I need to tune up Apache or MySQL? Or, I need to set-up Firefox for giving more connections?

The problem is that all your requests are using the same process, and that process is busy generating the Excel file. The trick would be to spawn a new process that can take care of the generation, something like this:http://www.welldonesoft.com/technolo...s/php/forking/

The problem is that all your requests are using the same process, and that process is busy generating the Excel file. The trick would be to spawn a new process that can take care of the generation, something like this:http://www.welldonesoft.com/technolo...s/php/forking/

Haha, I have had the idea of using exec just before leaving office, but I just couldn't work it out. Thanks a lot!!

Which folder should I use (instead of /usr/bin/php) if I run Apache on Windows?

I would advice you to write the code so that you don't need to pass variables. Insert everything you need into the database, basically make a queue of files to generate, and just let the Excel generating code work on that queue and nothing else. That way, you can call the Excel generating code from anyware, or set up a scheduled task to process the queue every five minutes or so.

I would advice you to write the code so that you don't need to pass variables. Insert everything you need into the database, basically make a queue of files to generate, and just let the Excel generating code work on that queue and nothing else. That way, you can call the Excel generating code from anyware, or set up a scheduled task to process the queue every five minutes or so.

I did it in ajax because I want users to know immediately once the excel file is created.

Anyway, thanks for your advice. I try to figure out another way to get the result.

Your queue processing code would of course update the database once the file is generated. You can then have an interval set up to poll the server to see if the file has been generated, and it's up to you to decide how often you want to poll the server. If you know that it takes about 30 seconds to generate it, wait 30 seconds before you start polling the server, and after that, send a new request every five seconds until it's been generated.

Your queue processing code would of course update the database once the file is generated. You can then have an interval set up to poll the server to see if the file has been generated, and it's up to you to decide how often you want to poll the server. If you know that it takes about 30 seconds to generate it, wait 30 seconds before you start polling the server, and after that, send a new request every five seconds until it's been generated.

Yeah I know it. But currently there are quite many polling on the site (actually it is a internal system for a company). I may want to avoid using too many polling.

Are you using php sessions? If the 30 second script uses sessions, then for 30 seconds you won't be able to load any other php script which uses sessions. There's simple ways around it if this is your problem.