html5 - PHP asynchronous tasks - sending results to browser when ready -


in php, want run several independent tasks in parallel. each task produces result want send visitor's browser results ready. idea use load page , use html5 sse (server-sent events) send data browser becomes available, while keeping http connection open keep-alive. not want flush output; doing quite few different tasks perfect candidates running in parallel, not want perform them synchronously.

my initial thought multi-threading pthreads extension. not sure how threads work php; connection browser kept open long have thread running, i.e. can safely send data browser threads? think pthreads pretty stable, not convinced should use because experimental.

pthreads was, , is, experiment pretty results. of limitations or features may change @ time; nature of experimentation.

then remembered gearman, allows me use workers tasks. background workers need because not want script execution block while waiting jobs finish, want run several jobs in parallel. no problem gearman, quite unsure can send results gearman client if use background workers. understood, background workers run in own processes or contexts, guess means cannot send data browser background workers? noticed gearmanclient class provides few methods setting callbacks, far read research, seems if these callbacks invoked synchronous calls. ideally, either want send results directly background workers (i doubt it's possible), or have background workers notify client when finishes, without having probe gearman job statuses. callback handler optimal, send data there.

i considered using messaging system (or memcached) such activemq zendqueue. idea send worker requests on channel , listen on different channel results. when message read result channel, message sent directly browser. downside doing additional work, such mapping result messages requests.

in end, leaning towards gearman approach, not sure if possible accomplish want. sum up, want perform parallel tasks take few seconds each , send them browser individually results ready (by using html5 sse).

are approaches possible? have other ideas? lot in advance!

i can answer pthreads part.

as yet, persistent threads not supported, @ end of each request, created contexts destroyed (joined). sending data directly threads browser bad idea (and in setups cause crash), reason there's no control @ level of zend on output of apache or whatever sapi using, pthreads makes no effort hook stdout's or of ... idea should have thread (or process) accepted connection deal output client, using data threads creates...

persistent threads bit problematic, persistent objects not supported in php, way mysqli etc provide persistent objects different thing pthreads requires persistent threads, firstly, interface same (ie, implements mysqli), pthreads implemented in php user. if work around problem, can envisage them being misunderstood easily, experiments persistent threads continue, documentation updated if or when find suitable implementation.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -