Reply to Re: Multithreading for standalone php

Your name:

Reply:


Posted by Chung Leong on 05/15/06 18:55

tony@tony.com wrote:
> This is interesting. I'm working on a project that will need to connect
> to 2 different servers and to speed things up (being ssl) I was hoping to
> be able to do this simultaneously.
>
> I need my web visitor to hit a button and be able to enter information
> on another server while at the same time my system is looking up data
> in a database on a third server.
>
> Would this be the sort of thing possible with PHP (my server uses apache2
> with CGI) or would it have to use threads?
>
> tony

The easiest way to do multitasking in PHP is to let the web server
handle the processes/threads. Instead of doing the time consuming task
directly--in this case retrieving data from a remote server--use a
child script, which the parent script then request multiple times.

In the child script, the first thing you do is call flush() so that an
fopen() to it would return immediately (flushing sends the HTTP
header). After that, proceed with doing the time-consuming task,
echoing whatever the result is.

In the parent script, connect to instances of the child script via
fopen(), storing the handles in an array. Use stream_set_blocking() to
make the streams non-blocking. Then use stream_select() to check which
streams has data available to read.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация