Page 1 of 1

Calling a function in background

Posted: Fri Jul 29, 2011 11:06 am
by rkatl
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.

Re: Calling a function in background

Posted: Fri Jul 29, 2011 5:06 pm
by Benjamin
No

Re: Calling a function in background

Posted: Fri Jul 29, 2011 10:26 pm
by Jonah Bron
Benjamin wrote:No
That made me smile :)

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

Posted: Sat Jul 30, 2011 12:39 am
by Benjamin
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

Posted: Sat Jul 30, 2011 6:22 am
by Weirdan
However you can surely fire up a Gearman job in the background: www.google.com/search?q=gearman+php

Re: Calling a function in background

Posted: Sat Jul 30, 2011 12:05 pm
by Jonah Bron
@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]

Re: Calling a function in background

Posted: Mon Aug 01, 2011 11:42 am
by adbertram

Re: Calling a function in background

Posted: Mon Aug 01, 2011 4:16 pm
by Jonah Bron
@adbertram: since it creates a new process and doesn't actually use threads, it's basically the same as PCNTL without the extra functionality.