Calling a function in background

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
rkatl
Forum Newbie
Posts: 17
Joined: Tue Apr 22, 2008 8:20 pm

Calling a function in background

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Calling a function in background

Post by Benjamin »

No
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Calling a function in background

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Calling a function in background

Post by Benjamin »

I was reading that, trying to figure out if I had actually written that at some point in the past.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Calling a function in background

Post by Weirdan »

However you can surely fire up a Gearman job in the background: www.google.com/search?q=gearman+php
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Calling a function in background

Post 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]
adbertram
Forum Newbie
Posts: 10
Joined: Sun Jul 31, 2011 10:18 pm

Re: Calling a function in background

Post by adbertram »

User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Calling a function in background

Post 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.
Post Reply