Welcome Guest, Not a member yet? Register   Sign In
How can one use multi threading in PHP applications ?
#7

(This post was last modified: 02-12-2017, 05:46 PM by skunkbad.)

(02-12-2017, 04:41 PM)iamthwee Wrote: Yes but that is not really multi-threading or utilising parallel processing.

Golang uses the concept of Go routines which are effectively cheap threads. It's definitely worth a read as the syntax is much easier than the threading you would use in either c or c++ and much safer to use.

https://www.youtube.com/watch?v=cN_DpYBzKso

Nodejs is more popular than golang and is the go to for such things nowadays, I think it is single threaded though although you could do something with callbacks. The only trouble is, is it is javascript syntax which I don't particularly enjoy using haha.

I watched about 2/3 of the video. I understand that using php's exec by itself would not utilize multi-threading or parallel processing, but it does allow PHP's execution to continue while the command or script run by exec is it's own process.

Regardless of language, I don't have the programming experience to know exactly when I would need true multi-threading. When I'm making Android apps I know I am forced to use a different thread for certain things, but I am not actually doing the hard work there, but instead relying on RxAndroid.

So if the OP really wants to do true multi-threading, then I don't have the answers. If OP wants to do two+ things at once, using the little library I linked to really does work. For my own needs I made some very slight tweaks to it, and it definitely creates new linux processes that can be verified through ps.

PHP Code:
/**
 * Start a background process using the Background_process library.
 */
public function start_background_process()
{
    
$this->load->library('background_process');

    
$pid $this->background_process->runFCPATH 'sh/background_process_test.sh' );

    echo 
anchor('test/monitor_background_process/' $pid'Check if it is running' );
}

// -----------------------------------------------------------------------

/**
 * Monitor the created background process (keep hitting F5)
 */
public function monitor_background_process$pid )
{
    
$this->load->library('background_process');

    echo 
'Running: ' $this->background_process->is_running$pid );
}

// ----------------------------------------------------------------------- 
Reply


Messages In This Thread
RE: How can one use multi threading in PHP applications ? - by skunkbad - 02-12-2017, 05:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB