Hello,
Is there a way to call a function in the background and should not wait for the main function for its response?
For example, in the below function, we need to fire function2(string1) by taking arguments from function1 but function1 call should not wait for function2 call to complete. This is on Zend framework.
function1(string1) {
function2(string1);
return something;
}
Any pointers appreciated.
Calling a function in background
Moderator: General Moderators
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Calling a function in background
That made me smileBenjamin wrote:No
In-between the lines of what Benjamin wrote, it reads...
Benjamin wrote:PHP is a single-threaded language, it makes no provision for multi-threading. The closest thing to it is PCNTL, which forks the entire process. The overhead on that is very high, and doesn't ofter have a valid application. See the manual for more info on that:
http://php.net/pcntl
Re: Calling a function in background
I was reading that, trying to figure out if I had actually written that at some point in the past.
Re: Calling a function in background
However you can surely fire up a Gearman job in the background: www.google.com/search?q=gearman+php
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Calling a function in background
@Weirdan hey, that's pretty sweet, never heard of that before; that's actually very applicable to a project I'm working on.
[via droidx]
[via droidx]
Re: Calling a function in background
What about something like this? http://robert.accettura.com/blog/2006/0 ... -with-php/
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Calling a function in background
@adbertram: since it creates a new process and doesn't actually use threads, it's basically the same as PCNTL without the extra functionality.