开发者

PHP hangs on multiple requests

Hi everyone I have a problem.

I have made a script where user submits a details. Details are saved to database and a exec is called after they are saved. The background scipt that is called is a php script that I call it via exec with wget:

session_write_close();
@exec('wget -q  -o /dev/null -a /dev/null -O /home/linux/test.txt http://127.0.0.1/admin/install.php?s=' . session_id() . '  > /dev/null 2>&1 &');

the script queries database and posts some parameters to external url with curl and waits for response.

I am unable to open any other php page (status bar shows: waiting for 127.0.0.1) on the webserver until the script execution of the script above ends. What I want is to run in background while I do other things on my website.

Apache/2.2.9 (Debian) mod_fastcgi/2.4.6 PHP/5.2.6-1+lenny9 with Suhosin-Patch Server at 127.0.0.1 Debian Linux distro. Server A开发者_JS百科PI CGI/FastCGI


http://pl2.php.net/manual/en/function.session-write-close.php

I assume you want server script to wait with sleep() timed interval for an AJAX event to trigger a server response / polling. Use session_write_close() before each sleep() iteration to make it work. I did a simple online chat using this pattern and it worked as charm.

The crucial thing was to prevent receiver AJAX script from constantly polling the server for updates in order to get fast response. Instead it requests script which sleeps and doesn't send any response untill reasonable timeout or an event occurs on server side.


If you are using file based sessions, they will lock the pages until they have been closed at end of script or explicitly via session_write_close().

If not, look for other things that are locking resources.


Hi thanks for the link. After reading I realized that I need to call session_write_close() after I use the data, because all pages were session handled (the reason I could not open anyting because php waits for session to be closed after execution of the the script in background.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜