Re: [PHP] Question about apache-php concurrent process control
Thank you Richard, I think I'd better explain a little about the project and then you or somebody else might give some good suggestion upon the restrictions of the project. The project is to implement a digital library protocol, called oai_pmh (http://www.openarchives.org/OAI/openarchivesprotocol.html) It acts as a broker for the harvester client to get meta data from libraries that have Z39.50 server. The database resides on libraries, and vary alot in speed, number of records, way to accept connection from z39.50 client. The number of records from some libraries might be over million. So the part that getting data from those libraries behave very differently. The harvester client sends http request, normally through program, like perl LWP. It normally sets 180 time out for connection. According to the protocol, the oai_pmh data provider act on respond to harvester http request, it begin to connect to specific library's z39.50 server, get data in, write them to disk, and translate to another xml format, then send to harvester client. If the records are too many, oai_pmh should send back partial data with resumption token. The harvester can later send out http request with same url but with the resumption token as one of the POST variable to get further data records. This process can be continueing till all the records has been send. Thus I noramlly use perl program to send the http request and get content instead of BROWSER. The behavior of buffer should not due to the setting of the browser. I can not echo the metadata directly back, since xlst need to use to transform and new xml file(s) are writen. The header() redirction is very nature to use if it can close the connection before I do something very time consumming after that. The exec with and the cron job are hard to use, since connection to z39.50 with a lot of state variables like connection id, etc can not easily be passed to another script. The harvester user normally is not a human with browser but a piece of code, while looping and sending out http requests if the page it gets back has resumptionToken tag. (it replace the element between open and close tag of resumptionToken, append to the next http request as POST variable for next records page). But the problem is each http request posts a timeout of 180 seconds. Thus I have to return partical data within 3 minutes while the whole process might take hours or even days. Then the process continue to get data from library server and transform it, then write to disk in a particular directory. The next request with resumption token comes in, the program will check for the existing of the directory and return if yes. If not existing, program will check to return within 3 minutes or send back not available information. Sorry for the long writting. I hope some one has some suggestion for me. Thank you very much. --- I now encounter a problem with flow control of my program with PHP. This is very crucial to the design of a pretty big project. This is what I want to do in the program: ?php do_A(); header(Location: .$result_of_do_A); Depending on the buffering options in php.ini and/or Apache, this may or may not just end your program, as I understand it. Once you send the Location header, everything else is irrelevant, or at least not reliable. You could do: echo $result_of_do_A; flush(); and the user will see what happened with A, while waiting for B. do_B(); ? Since it takes do_B() quite a while to finish, so I want the http client get the partial result from do_A() by redirect a page to them before start do_B(). But it seems that the redirection will only occure after the entire php program finishes, i.e., after do_B(). I sent http request through browser, curl comman line with -N (no buffer) option and with a perl LWP program I wrote. All of them suggest that header(), although is put before do_B() in code, gets executed only after all the php code finished. I add flush() after header() too, but no work. If that is what you are seeing happen, you probably have output buffering turned on The Location: header is acted upon by the BROWSER, not by PHP, not by your server. The BROWSER sees that header and then jumps to somewhere else. My question is: Is there any way that I can return to the client though http response and then continue my progress with my program? You could also look into the pcntl stuff to fork() or, depending on various settings, you might get: exec(do_B() ); to get B to happen in the background. With all that said: As a general rule, when I found myself doing this kind of stuff, I later realized that I hadn't really designed my application very well for an end-user experience. If it takes THAT long to finish B, then you're probably MUCH better off putting something in a ToDo List in your database, and
Re: [PHP] Question about apache-php concurrent process control
Read this chapter of the manual: http://www.php.net/manual/en/features.connection-handling.php Liang ZHONG wrote: I now encounter a problem with flow control of my program with PHP. This is very crucial to the design of a pretty big project. This is what I want to do in the program: ?php do_A(); header(Location: .$result_of_do_A); do_B(); ? Since it takes do_B() quite a while to finish, so I want the http client get the partial result from do_A() by redirect a page to them before start do_B(). But it seems that the redirection will only occure after the entire php program finishes, i.e., after do_B(). I sent http request through browser, curl comman line with -N (no buffer) option and with a perl LWP program I wrote. All of them suggest that header(), although is put before do_B() in code, gets executed only after all the php code finished. I add flush() after header() too, but no work. My question is: Is there any way that I can return to the client though http response and then continue my progress with my program? Thank you very much for your kindly help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
On Tue, July 19, 2005 5:32 am, Liang ZHONG said: It sounds interesting. But since I am pretty new to PHP, I have some questions, naive maybe, about what you wrote. #!/bin/sh\n/path/to/script/Send.php 12 \n What does the Send.php look like? I do not have idea how a shell interprets an php script and what the parameter 12 means here. If you do not mind, could you please also let me look at your Send.php? I dunno what his Send script looks like, but that 12 isn't a 12 at all. It's a 1 with a symbol and then a 2. The symbol probably got eaten by somebody's email program somewhere along the way. See, in some Linux/Un*x shells (errr, like DOS prompt only not broken) there is the idea of standard output which is where your basic output messages go. There is also standard error where your ERROR messages go. On Linux/Unix file systems, stdout (standard output) is bound to a special file which lives in /dev/1 -- it's not really really a file, but a device but to send stuff to the standard output -- which is generally your screen, you can just write it to /dev/1 and it gets there. For shorthand, in shell scripts, you can just use 1 to mean /dev/1 Similarly, standard error is /dev/2 and you can use 2 So, what he really had was 12 which was saying: Take anything that was supposed to go to 1 (standard output) and send it (the symbol) into 2 (standard error) So he's telling the shell (operating system) to combine any normal output into the error output so it's one big mess of output. You can learn more about this stuff (though it may be a bit overwhelming at first) by searching for man bash or reading an introductory Linux textbook or resource on-line. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
I now encounter a problem with flow control of my program with PHP. This is very crucial to the design of a pretty big project. This is what I want to do in the program: ?php do_A(); header(Location: .$result_of_do_A); do_B(); ? Since it takes do_B() quite a while to finish, so I want the http client get the partial result from do_A() by redirect a page to them before start do_B(). But it seems that the redirection will only occure after the entire php program finishes, i.e., after do_B(). I sent http request through browser, curl comman line with -N (no buffer) option and with a perl LWP program I wrote. All of them suggest that header(), although is put before do_B() in code, gets executed only after all the php code finished. I add flush() after header() too, but no work. My question is: Is there any way that I can return to the client though http response and then continue my progress with my program? Thank you very much for your kindly help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
http://ca.php.net/manual/en/function.register-shutdown-function.php Cheers, Rob. On Thu, 2005-07-21 at 23:40, Liang ZHONG wrote: I now encounter a problem with flow control of my program with PHP. This is very crucial to the design of a pretty big project. This is what I want to do in the program: ?php do_A(); header(Location: .$result_of_do_A); do_B(); ? Since it takes do_B() quite a while to finish, so I want the http client get the partial result from do_A() by redirect a page to them before start do_B(). But it seems that the redirection will only occure after the entire php program finishes, i.e., after do_B(). I sent http request through browser, curl comman line with -N (no buffer) option and with a perl LWP program I wrote. All of them suggest that header(), although is put before do_B() in code, gets executed only after all the php code finished. I add flush() after header() too, but no work. My question is: Is there any way that I can return to the client though http response and then continue my progress with my program? Thank you very much for your kindly help. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
On Thu, July 21, 2005 8:40 pm, Liang ZHONG said: I now encounter a problem with flow control of my program with PHP. This is very crucial to the design of a pretty big project. This is what I want to do in the program: ?php do_A(); header(Location: .$result_of_do_A); Depending on the buffering options in php.ini and/or Apache, this may or may not just end your program, as I understand it. Once you send the Location header, everything else is irrelevant, or at least not reliable. You could do: echo $result_of_do_A; flush(); and the user will see what happened with A, while waiting for B. do_B(); ? Since it takes do_B() quite a while to finish, so I want the http client get the partial result from do_A() by redirect a page to them before start do_B(). But it seems that the redirection will only occure after the entire php program finishes, i.e., after do_B(). I sent http request through browser, curl comman line with -N (no buffer) option and with a perl LWP program I wrote. All of them suggest that header(), although is put before do_B() in code, gets executed only after all the php code finished. I add flush() after header() too, but no work. If that is what you are seeing happen, you probably have output buffering turned on The Location: header is acted upon by the BROWSER, not by PHP, not by your server. The BROWSER sees that header and then jumps to somewhere else. My question is: Is there any way that I can return to the client though http response and then continue my progress with my program? You could also look into the pcntl stuff to fork() or, depending on various settings, you might get: exec(do_B() ); to get B to happen in the background. With all that said: As a general rule, when I found myself doing this kind of stuff, I later realized that I hadn't really designed my application very well for an end-user experience. If it takes THAT long to finish B, then you're probably MUCH better off putting something in a ToDo List in your database, and doing B later in a cron job. Then notify the user through email or some kind of status display that they will see on your site frequently when B is done NEVER make the user sit around waiting for your server. Human time is far far far too precious (and expensive!) to waste it sitting around doing nothing useful waiting for your program to finish. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
Thank you Rouvas, I never used the tools you mentioned. But I will definitely give them a try. I wrote a perl script using LWP as an http user agent. and the timing function you suggested. It works well. I am new to this forum, and new to PHP. It seems Rasmus is famous, and I should have shown my respect. Thanks again all of you for your kindly help. Hi Liang, trying to get conclusive results with browsers is futile. Use a command-line tool (like curl) to invoke the web pages and get the results. Or you can use PHP's own function to query the web server and do your own timing with microtime() function or another suitable for your purposes. In order for flush() results to reach you (in a browser) they have to pass from multiple caches like PHP's, Apache's, the occasional proxies and finally the browser's own cache. So you cannot get dependaple results measuring times or responses from your browser. Try the methods above. And a final tip... When Rasmus speaks, you don't question him:-) Period. Have a nice day, -Stathis -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Question about apache-php concurrent process control
snipIt seems Rasmus is famous, and I should have shown my respect./snip history src = 'php_manual_en.chm' PHP succeeds an older product, named PHP/FI. PHP/FI was created by Rasmus Lerdorf in 1995, initially as a simple set of Perl scripts for tracking accesses to his online resume. He named this set of scripts 'Personal Home Page Tools'. As more functionality was required, Rasmus wrote a much larger C implementation, which was able to communicate with databases, and enabled users to develop simple dynamic Web applications. Rasmus chose to release the source code for PHP/FI for everybody to see, so that anybody can use it, as well as fix bugs in it and improve the code. /history This message has been delivered to the Internet by the Revenue Internet e-mail service * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
Hi André, It sounds interesting. But since I am pretty new to PHP, I have some questions, naive maybe, about what you wrote. #!/bin/sh\n/path/to/script/Send.php 12 \n What does the Send.php look like? I do not have idea how a shell interprets an php script and what the parameter 12 means here. If you do not mind, could you please also let me look at your Send.php? Thank you very much. I did something like that for a newsletter sending script. Basiclly, I had two scripts: a) AddEdit.php that would list the newsletter's items and allow it to send b) Send.php that was a script I ran on the background When pressed Send on AddEdit, it would do something like $tempName = tempnam( '/tmp', 'newsletter' ); $fp = fopen( $tempName, 'w+' ); fputs( $fp, #!/bin/sh\n/path/to/script/Send.php 12 \n ); fclose( $fp ); chmod( $tempName, 0755 ); system( $tempName . ' ' ); That way, it would launch the second script into the background, checking if the script altered the newsletter's state for Sent everytime a user saw the newsletter's details. Hope it helped. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Question about apache-php concurrent process control
Can somebody here help me to delete my message? People who read this must be laughing at me. :) snipIt seems Rasmus is famous, and I should have shown my respect./snip history src = 'php_manual_en.chm' PHP succeeds an older product, named PHP/FI. PHP/FI was created by Rasmus Lerdorf in 1995, initially as a simple set of Perl scripts for tracking accesses to his online resume. He named this set of scripts 'Personal Home Page Tools'. As more functionality was required, Rasmus wrote a much larger C implementation, which was able to communicate with databases, and enabled users to develop simple dynamic Web applications. Rasmus chose to release the source code for PHP/FI for everybody to see, so that anybody can use it, as well as fix bugs in it and improve the code. /history This message has been delivered to the Internet by the Revenue Internet e-mail service * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
I did something like that for a newsletter sending script. Basiclly, I had two scripts: a) AddEdit.php that would list the newsletter's items and allow it to send b) Send.php that was a script I ran on the background When pressed Send on AddEdit, it would do something like $tempName = tempnam( '/tmp', 'newsletter' ); $fp = fopen( $tempName, 'w+' ); fputs( $fp, #!/bin/sh\n/path/to/script/Send.php 12 \n ); fclose( $fp ); chmod( $tempName, 0755 ); system( $tempName . ' ' ); That way, it would launch the second script into the background, checking if the script altered the newsletter's state for Sent everytime a user saw the newsletter's details. Hope it helped. On 7/16/05, Rory Browne [EMAIL PROTECTED] wrote: On 7/16/05, rouvas [EMAIL PROTECTED] wrote: Hi Liang, trying to get conclusive results with browsers is futile. Use a command-line tool (like curl) to invoke the web pages and get the results. Or you can use Although personally I think that telnet-to-port-80 would be a better idea, in this case when you're trying to check what is outputted first. Either that or a TCP sniffer. I also agree with the microtime() suggestion, mentioned below. It will get you around the problem of caches - which is a major problem for something like this. I'm not sure what the situation with apache is regarding caches. PHP's own function to query the web server and do your own timing with microtime() function or another suitable for your purposes. In order for flush() results to reach you (in a browser) they have to pass from multiple caches like PHP's, Apache's, the occasional proxies and finally the browser's own cache. So you cannot get dependaple results measuring times or responses from your browser. Try the methods above. And a final tip... When Rasmus speaks, you don't question him:-) Period. Unless you didn't understand what he said and want clarification. Have a nice day, -Stathis On Saturday 16 July 2005 04:41, Liang ZHONG wrote: Hi Rasmus, You are right. It was the problem with the browser. I used Mozilla Firefox to try, and do not know what consideration it just serialized the identical url http requests. I then turned to use 2 IE 6.0 windows, 2 tabs within Maxthon browser, one IE windows and one Firefox, to test. Then I got the conclusion as you told. Thank you very much for the help. BTW, I could not get the flush() work, neither flush() with ob_flush(). I tried almost all methods mentioned in the followed posts under http://us2.php.net/flush, but none of them can really pushed the buffer out. The site is configurated with http://liang.ns2user.info/php/info.php on Red head, kernel 2.4.29. What can I do to get it work? Thank you again. Liang ZHONG wrote: Could you please explain it a little bit more? I did test this way. The code is the same for a.php and b.php ?php sleep(20); print Done. br /; ? I place request from 2 browser windows. First time, I placed with http://baseURL/a.php with both 2 browsers, starting times have 5 second interval. Then the first Done shows after 20 seconds and the second Done shows 20 seconds after the first Done. Then, I placed one browser with http://baseURL/a.php and the second one with http://baseURL/b.php, with starting time of 5 second interval. Then I got the first browser showing Done after 20 seconds and 5 seconds later, the second browser showed Done, too. Thus it seems that the apache can spoon out multiple php interpreters responding to http requests, while php can not deal with concurrent process from one program. I have no idea what you did to configure it this way. I wouldn't even know how to do that if you asked me to. As far as PHP is concerned it has no idea which processes are handling which script files at any one point. So whether you request a.php and b.php at the same time or a.php twice at the same time, it makes absolutely no difference to PHP. If you are really seeing this, then the limitation is in your browser or somewhere else. Try making a.php output stuff so it becomes easier to see. As in for($i=0;$i20;$i++) { echo $i; flush(); sleep(1); } You should see the counter start counting as soon as you hit the page. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
Hi Liang, trying to get conclusive results with browsers is futile. Use a command-line tool (like curl) to invoke the web pages and get the results. Or you can use PHP's own function to query the web server and do your own timing with microtime() function or another suitable for your purposes. In order for flush() results to reach you (in a browser) they have to pass from multiple caches like PHP's, Apache's, the occasional proxies and finally the browser's own cache. So you cannot get dependaple results measuring times or responses from your browser. Try the methods above. And a final tip... When Rasmus speaks, you don't question him:-) Period. Have a nice day, -Stathis On Saturday 16 July 2005 04:41, Liang ZHONG wrote: Hi Rasmus, You are right. It was the problem with the browser. I used Mozilla Firefox to try, and do not know what consideration it just serialized the identical url http requests. I then turned to use 2 IE 6.0 windows, 2 tabs within Maxthon browser, one IE windows and one Firefox, to test. Then I got the conclusion as you told. Thank you very much for the help. BTW, I could not get the flush() work, neither flush() with ob_flush(). I tried almost all methods mentioned in the followed posts under http://us2.php.net/flush, but none of them can really pushed the buffer out. The site is configurated with http://liang.ns2user.info/php/info.php on Red head, kernel 2.4.29. What can I do to get it work? Thank you again. Liang ZHONG wrote: Could you please explain it a little bit more? I did test this way. The code is the same for a.php and b.php ?php sleep(20); print Done. br /; ? I place request from 2 browser windows. First time, I placed with http://baseURL/a.php with both 2 browsers, starting times have 5 second interval. Then the first Done shows after 20 seconds and the second Done shows 20 seconds after the first Done. Then, I placed one browser with http://baseURL/a.php and the second one with http://baseURL/b.php, with starting time of 5 second interval. Then I got the first browser showing Done after 20 seconds and 5 seconds later, the second browser showed Done, too. Thus it seems that the apache can spoon out multiple php interpreters responding to http requests, while php can not deal with concurrent process from one program. I have no idea what you did to configure it this way. I wouldn't even know how to do that if you asked me to. As far as PHP is concerned it has no idea which processes are handling which script files at any one point. So whether you request a.php and b.php at the same time or a.php twice at the same time, it makes absolutely no difference to PHP. If you are really seeing this, then the limitation is in your browser or somewhere else. Try making a.php output stuff so it becomes easier to see. As in for($i=0;$i20;$i++) { echo $i; flush(); sleep(1); } You should see the counter start counting as soon as you hit the page. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
On 7/16/05, rouvas [EMAIL PROTECTED] wrote: Hi Liang, trying to get conclusive results with browsers is futile. Use a command-line tool (like curl) to invoke the web pages and get the results. Or you can use Although personally I think that telnet-to-port-80 would be a better idea, in this case when you're trying to check what is outputted first. Either that or a TCP sniffer. I also agree with the microtime() suggestion, mentioned below. It will get you around the problem of caches - which is a major problem for something like this. I'm not sure what the situation with apache is regarding caches. PHP's own function to query the web server and do your own timing with microtime() function or another suitable for your purposes. In order for flush() results to reach you (in a browser) they have to pass from multiple caches like PHP's, Apache's, the occasional proxies and finally the browser's own cache. So you cannot get dependaple results measuring times or responses from your browser. Try the methods above. And a final tip... When Rasmus speaks, you don't question him:-) Period. Unless you didn't understand what he said and want clarification. Have a nice day, -Stathis On Saturday 16 July 2005 04:41, Liang ZHONG wrote: Hi Rasmus, You are right. It was the problem with the browser. I used Mozilla Firefox to try, and do not know what consideration it just serialized the identical url http requests. I then turned to use 2 IE 6.0 windows, 2 tabs within Maxthon browser, one IE windows and one Firefox, to test. Then I got the conclusion as you told. Thank you very much for the help. BTW, I could not get the flush() work, neither flush() with ob_flush(). I tried almost all methods mentioned in the followed posts under http://us2.php.net/flush, but none of them can really pushed the buffer out. The site is configurated with http://liang.ns2user.info/php/info.php on Red head, kernel 2.4.29. What can I do to get it work? Thank you again. Liang ZHONG wrote: Could you please explain it a little bit more? I did test this way. The code is the same for a.php and b.php ?php sleep(20); print Done. br /; ? I place request from 2 browser windows. First time, I placed with http://baseURL/a.php with both 2 browsers, starting times have 5 second interval. Then the first Done shows after 20 seconds and the second Done shows 20 seconds after the first Done. Then, I placed one browser with http://baseURL/a.php and the second one with http://baseURL/b.php, with starting time of 5 second interval. Then I got the first browser showing Done after 20 seconds and 5 seconds later, the second browser showed Done, too. Thus it seems that the apache can spoon out multiple php interpreters responding to http requests, while php can not deal with concurrent process from one program. I have no idea what you did to configure it this way. I wouldn't even know how to do that if you asked me to. As far as PHP is concerned it has no idea which processes are handling which script files at any one point. So whether you request a.php and b.php at the same time or a.php twice at the same time, it makes absolutely no difference to PHP. If you are really seeing this, then the limitation is in your browser or somewhere else. Try making a.php output stuff so it becomes easier to see. As in for($i=0;$i20;$i++) { echo $i; flush(); sleep(1); } You should see the counter start counting as soon as you hit the page. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Question about apache-php concurrent process control
I am a programmer and new to php. I wonder what process control can php interpreter do for multithreading . I notice that through http request, php interpreter can execute 2 php programs simataneously, but will only sequentially queued and execute if I try to execute one php code in the same time. Can somebody tell me is it a problem by php design not to be execute code concurrently, or some apache/php configuration problem where I can fix? Thank you very much -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Question about apache-php concurrent process control
I am a programmer and new to php. I wonder what process control can php interpreter do for multithreading . I notice that through http request, php interpreter can execute 2 php programs simataneously, but will only sequentially queued and execute if I try to execute one php code in the same time. Can somebody tell me is it a problem by php design not to be execute code concurrently, or some apache/php configuration problem where I can fix? Thank you very much -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
Liang wrote: I am a programmer and new to php. I wonder what process control can php interpreter do for multithreading . I notice that through http request, php interpreter can execute 2 php programs simataneously, but will only sequentially queued and execute if I try to execute one php code in the same time. Can somebody tell me is it a problem by php design not to be execute code concurrently, or some apache/php configuration problem where I can fix? Apache is a multi-process single-threaded architecture. 1 request, 1 process. Concurrent requests are handled by concurrent processes. What is it you think you need a second thread for during a request? -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
As I know, apache-php works this way. When the web server gets an http request with file name extension .php, it will start the php interpreter to process the php file. Now I have a php program does something like this: when it is executing with one parameter p1, the program code goes to contact a database, gets back huge amount of data, writes it to file system. This will take pretty long time to finish. In the mean time, the same php code will be invoked by apache with another request, passing different parameter p2, indicates the code need to run to check the availability and read partial of the data which has already writen to the file system just now. The program location need to be in the same URL, but with only different parameter passing to it. for example: http://baseURL/a.php?v=p1 http://baseURL/a.php?v=p2 I want these 2 process can be run concurrently, but through a small test, I found out that they just sequentially execute one after the other. http://baseURL/a.php http://baseURL/b.php howevery can run concurrently well, it means that apache can invoke multiple php interpreter processes. But I do not know how to make php interpreter to do the same thing. Or 2 php interpreter processes process one php program sepreately without interfer with each other. Hope I have explained myself clearly. Thank you. From: Rasmus Lerdorf [EMAIL PROTECTED] To: Liang [EMAIL PROTECTED] CC: php-general@lists.php.net Subject: Re: [PHP] Question about apache-php concurrent process control Date: Fri, 15 Jul 2005 13:46:37 -0700 Liang wrote: I am a programmer and new to php. I wonder what process control can php interpreter do for multithreading . I notice that through http request, php interpreter can execute 2 php programs simataneously, but will only sequentially queued and execute if I try to execute one php code in the same time. Can somebody tell me is it a problem by php design not to be execute code concurrently, or some apache/php configuration problem where I can fix? Apache is a multi-process single-threaded architecture. 1 request, 1 process. Concurrent requests are handled by concurrent processes. What is it you think you need a second thread for during a request? -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
Liang ZHONG wrote: As I know, apache-php works this way. When the web server gets an http request with file name extension .php, it will start the php interpreter to process the php file. Now I have a php program does something like this: when it is executing with one parameter p1, the program code goes to contact a database, gets back huge amount of data, writes it to file system. This will take pretty long time to finish. In the mean time, the same php code will be invoked by apache with another request, passing different parameter p2, indicates the code need to run to check the availability and read partial of the data which has already writen to the file system just now. The program location need to be in the same URL, but with only different parameter passing to it. for example: http://baseURL/a.php?v=p1 http://baseURL/a.php?v=p2 I want these 2 process can be run concurrently, but through a small test, I found out that they just sequentially execute one after the other. Sorry, your test is wrong then. Apache/PHP does not serialize requests like that. If somehow the backend you are collecting data from is serializing the requests, then you are out of luck and frontend threads isn't going to solve that since your threads would simply be serialized as well. You are on the wrong track here. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
Could you please explain it a little bit more? I did test this way. The code is the same for a.php and b.php ?php sleep(20); print Done. br /; ? I place request from 2 browser windows. First time, I placed with http://baseURL/a.php with both 2 browsers, starting times have 5 second interval. Then the first Done shows after 20 seconds and the second Done shows 20 seconds after the first Done. Then, I placed one browser with http://baseURL/a.php and the second one with http://baseURL/b.php, with starting time of 5 second interval. Then I got the first browser showing Done after 20 seconds and 5 seconds later, the second browser showed Done, too. Thus it seems that the apache can spoon out multiple php interpreters responding to http requests, while php can not deal with concurrent process from one program. I do not know if it is due to the php's design limitation, or I did not configure the php correctly to fulfill its full functionality? Thank you Liang ZHONG wrote: As I know, apache-php works this way. When the web server gets an http request with file name extension .php, it will start the php interpreter to process the php file. Now I have a php program does something like this: when it is executing with one parameter p1, the program code goes to contact a database, gets back huge amount of data, writes it to file system. This will take pretty long time to finish. In the mean time, the same php code will be invoked by apache with another request, passing different parameter p2, indicates the code need to run to check the availability and read partial of the data which has already writen to the file system just now. The program location need to be in the same URL, but with only different parameter passing to it. for example: http://baseURL/a.php?v=p1 http://baseURL/a.php?v=p2 I want these 2 process can be run concurrently, but through a small test, I found out that they just sequentially execute one after the other. Sorry, your test is wrong then. Apache/PHP does not serialize requests like that. If somehow the backend you are collecting data from is serializing the requests, then you are out of luck and frontend threads isn't going to solve that since your threads would simply be serialized as well. You are on the wrong track here. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
Liang ZHONG wrote: Could you please explain it a little bit more? I did test this way. The code is the same for a.php and b.php ?php sleep(20); print Done. br /; ? I place request from 2 browser windows. First time, I placed with http://baseURL/a.php with both 2 browsers, starting times have 5 second interval. Then the first Done shows after 20 seconds and the second Done shows 20 seconds after the first Done. Then, I placed one browser with http://baseURL/a.php and the second one with http://baseURL/b.php, with starting time of 5 second interval. Then I got the first browser showing Done after 20 seconds and 5 seconds later, the second browser showed Done, too. Thus it seems that the apache can spoon out multiple php interpreters responding to http requests, while php can not deal with concurrent process from one program. I have no idea what you did to configure it this way. I wouldn't even know how to do that if you asked me to. As far as PHP is concerned it has no idea which processes are handling which script files at any one point. So whether you request a.php and b.php at the same time or a.php twice at the same time, it makes absolutely no difference to PHP. If you are really seeing this, then the limitation is in your browser or somewhere else. Try making a.php output stuff so it becomes easier to see. As in for($i=0;$i20;$i++) { echo $i; flush(); sleep(1); } You should see the counter start counting as soon as you hit the page. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about apache-php concurrent process control
Hi Rasmus, You are right. It was the problem with the browser. I used Mozilla Firefox to try, and do not know what consideration it just serialized the identical url http requests. I then turned to use 2 IE 6.0 windows, 2 tabs within Maxthon browser, one IE windows and one Firefox, to test. Then I got the conclusion as you told. Thank you very much for the help. BTW, I could not get the flush() work, neither flush() with ob_flush(). I tried almost all methods mentioned in the followed posts under http://us2.php.net/flush, but none of them can really pushed the buffer out. The site is configurated with http://liang.ns2user.info/php/info.php on Red head, kernel 2.4.29. What can I do to get it work? Thank you again. Liang ZHONG wrote: Could you please explain it a little bit more? I did test this way. The code is the same for a.php and b.php ?php sleep(20); print Done. br /; ? I place request from 2 browser windows. First time, I placed with http://baseURL/a.php with both 2 browsers, starting times have 5 second interval. Then the first Done shows after 20 seconds and the second Done shows 20 seconds after the first Done. Then, I placed one browser with http://baseURL/a.php and the second one with http://baseURL/b.php, with starting time of 5 second interval. Then I got the first browser showing Done after 20 seconds and 5 seconds later, the second browser showed Done, too. Thus it seems that the apache can spoon out multiple php interpreters responding to http requests, while php can not deal with concurrent process from one program. I have no idea what you did to configure it this way. I wouldn't even know how to do that if you asked me to. As far as PHP is concerned it has no idea which processes are handling which script files at any one point. So whether you request a.php and b.php at the same time or a.php twice at the same time, it makes absolutely no difference to PHP. If you are really seeing this, then the limitation is in your browser or somewhere else. Try making a.php output stuff so it becomes easier to see. As in for($i=0;$i20;$i++) { echo $i; flush(); sleep(1); } You should see the counter start counting as soon as you hit the page. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php