PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Sep 19, 2020 11:40 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: thread in PHP
PostPosted: Tue Jun 19, 2012 3:41 am 
Offline
Forum Commoner

Joined: Wed Jul 01, 2009 3:35 am
Posts: 82
Location: Mumbai
I have a class which takes an array of data and processes it and returns it. For huge amount of data, it takes a lot of time.

I want to implement this in threads, but PHP has no threading library.

Can anyone help me to fix this ?


Top
 Profile  
 
 Post subject: Re: thread in PHP
PostPosted: Tue Jun 19, 2012 12:35 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
PHP is a technology embedded in a web server, so long running processes like this are probably best done elsewhere. You could, of course, just increase the connection timeout just for this purpose. Or you could get a faster server to reduce the time.

I would recommend running a separate program on the server to process this data. This could be in CLI PHP or some other language. There are technologies like Gearman that might help you with this.

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: thread in PHP
PostPosted: Tue Jun 19, 2012 2:26 pm 
Offline
Forum Contributor
User avatar

Joined: Thu May 11, 2006 8:58 pm
Posts: 305
Location: Utah, USA
is some code that uses `popen` and `pclose` to start a process from the command line and not wait for it to exit.


Top
 Profile  
 
 Post subject: Re: thread in PHP
PostPosted: Thu Jun 21, 2012 6:34 am 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
If you are running this code on a POSIX server (i.e. not Windows) then you probably want to use a combination of pcntl_fork() and pcntl_signal(). I believe it's useful to learn to use these UNIX concepts in any case, but they are quite difficult to get to grips with, especially if you need to share data between the running processes (which you would need to do with a socket pair, a TCP connection or a uni-directional pipe).

EDIT | I agree with Christoper, just to be clear ;) Don't try to force a browser to wait a long time for a long-running process. Background that work as much as possible. If you need to do background work on-demand, rather than via cron, look at a queueing system such as beanstalk (in combination with pheanstalk), or , in combination with Redis.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group