回复: [PHP-DEV] 回复: [PHP-DEV] How should I call a PHP function
| From: | Wei Dai | Date: | Tue, 19 Aug 2014 09:44:12 +0000 |
| Subject: | 回复: [PHP-DEV] 回复: [PHP-DEV] How should I call a PHP function | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-76696@lists.php.net to get a copy of this message | ||
> On Tue, 19 Aug 2014, Wei Dai wrote:
>
> > > On Mon, 18 Aug 2014, Wei Dai wrote:
> > >
> > > > > I'm trying to call a function inside a module, a PHP_FUNCTION.
> > > > > Other than zend_eval_stringl, what's the direct way to do it?
> > > > >
> > > >
> > > > Please refer to call_user_function and call_user_function_ex.
> > > >
> > >
> > >
> > > Actually, you need to be careful with this. If you are calling
> > > another PHP function in the same extension, do *not* use
> > > call_user_function. Instead, create a common C function that you
> > > can call from whereever you need to. call_user_function(_ex) is not
> > > fast.
> > >
> > >
> >
> > i agree.
> >
> > here is a scenario:
> >
> > i was wrote an extension, and i need to call some PHP function like
> > “strtr (http://lxr.php.net/s?defs=strtr&project=PHP_5_4)” “*trim" or
> > a function in another extension but it doesn’t have a common C
> > function. However, i don’t want to copy the implement code into my
> > extension.
> >
> > so, i have two options:
> >
> > 1. copy the duplicate code into my extension, It can be fast in this
> > way, but the code is not beautiful.
> >
> > 2. call call_user_function(_ex) , it’s slower than the first option,
> > but the code is more simple and beautiful than the first option.
> >
>
>
> or:
>
> 3. refactor the functionality in PHP so that trim or others *can* be
> used in extensions.
>
> I would not pick option 2, especially not if you're going to call this
> function a lot. Calling a PHP function directly involves a lot more
> overhead than just calling a C-function.
>
you are right.
the reason to write php extension, because we can get performance improvement.
cheer,
Wei Dai