SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    index.php
    - jobs_add.php [iframe]
    - javascript (including the ajax codes)

    1. jobs_add.php stores data
    2. jobs_add.php pass url to javascript to javascript in parent window
    3. javascript call ajax

    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.

    Could anyone please help finding out the problem? Thanks so much!

  2. #2
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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/

  4. #4
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wysiwyg View Post
    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?

  5. #5
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cannot pass data from the parent script to the script (which will be run by cmd) by using _GET or _POST. How to solve this?

    Thanks a lot!!

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wysiwyg View Post
    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.

  8. #8
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wysiwyg View Post
    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.

    Anyway, thanks so much!

  10. #10
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  11. #11
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tried out the method suggested by wysiwyg.

    It works if I type the command in cmd.exe on the server computer locally.
    "C:/xampp/php/php.exe C:/xampp/htdocs/task_generateJobSheets.php"

    However, it does not work if I run it as exec.
    exec("C:/xampp/php/php.exe C:/xampp/htdocs/task_generateJobSheets.php");

    The server is WinXP. So, I don't think there is something like UAC troubling me.
    Do I need to set any permission stuff?
    Or why doesn't it work?

    Please help... Thanks!

  12. #12
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have searched this out finally.
    http://tech.davidchiu.com/?s=psexec
    The script works with -accepteula together with exec("psexec C:\...php.exe")

    File could be generated now. (However, I could not find it afterward... phpexcel is very confusing on its include path...)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •