# Calling PHP functions from an extension

- Thread: https://externals.io/message/11462
- Original archive: https://news-web.php.net/php.internals/11462
- Started by John Lim on 2004-07-22T11:17:24+00:00
- Messages: 11
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #11462 — John Lim — 2004-07-22T11:17:24+00:00

URL: https://externals.io/message/11462#11462

Hi,

I am using call_user_function_ex() to call mysql_fetch_array, ocifetchinto,
etc.

 error = call_user_function_ex(EG(function_table),
      NULL,
      &function_name_zval,
      &retval, 2,  &params[1], 0, `NULL` TSRMLS_CC);

This is not giving me the performance I am looking for because the Zend
Engine
still has to  search for the function to call. Is there any way to get  a
function
pointer to mysql_fetch_array/ocifetchinto etc., and call the function
directly ?

Thanks in advance.

---

## #11463 — George Schlossnagle — 2004-07-22T12:41:26+00:00

URL: https://externals.io/message/11462#11463 · In reply to: #11462

> Hi,
>
> I am using call_user_function_ex() to call mysql_fetch_array, 
> ocifetchinto,
> etc.
>
>  error = call_user_function_ex(EG(function_table),
>       NULL,
>       &function_name_zval,
>       &retval, 2,  &params[1], 0, `NULL` TSRMLS_CC);
>
> This is not giving me the performance I am looking for because the Zend
> Engine
> still has to  search for the function to call. Is there any way to get 
>  a
> function
> pointer to mysql_fetch_array/ocifetchinto etc., and call the function
> directly ?

If performance is your concern, why not simply call the various RDBMS 
API functions directly?

George

---

## #11464 — John Lim — 2004-07-22T13:39:58+00:00

URL: https://externals.io/message/11462#11464 · In reply to: #11463

Hi George,

2 reasons.

High learning curve to learn all client API's.  Secondly because of linking
issues with the client. E.g. oracle might not be installed on the server.

John

>
> If performance is your concern, why not simply call the various RDBMS
> API functions directly?
>
> George

---

## #11465 — George Schlossnagle — 2004-07-22T13:47:07+00:00

URL: https://externals.io/message/11462#11465 · In reply to: #11464

> Hi George,
>
> 2 reasons.
>
> High learning curve to learn all client API's.

All the APIs have worked examples in the PHP sources. :)

> Secondly because of linking
> issues with the client. E.g. oracle might not be installed on the 
> server.

Of course you create a new runtime dependency your way.

Are you doing this for PHP5 or PHP4?  There's a worked example in the 
new xsl extension for PHP5 that does most of what you want (where PHP 
functions are registered as XSLT extension functions.)

George

---

## #11467 — Wez Furlong — 2004-07-22T14:08:21+00:00

URL: https://externals.io/message/11462#11467 · In reply to: #11464

Doesn't ext/dbx already do what you're doing?
To answer your original question, no, there isn't really a way to call
it directly without duplicating a lot of ugly code.

IIRC, PHP 5 adds a cache to reduce the lookup overhead for
call_user_function; you probably won't be able to get it to go much
faster than it does already.

--Wez.


> Hi George,
> 
> 2 reasons.
> 
> High learning curve to learn all client API's.  Secondly because of linking
> issues with the client. E.g. oracle might not be installed on the server.
> 
> John

---

## #11468 — Lester Caine — 2004-07-22T14:27:31+00:00

URL: https://externals.io/message/11462#11468 · In reply to: #11467

Wez Furlong wrote:

> Doesn't ext/dbx already do what you're doing?
> To answer your original question, no, there isn't really a way to call
> it directly without duplicating a lot of ugly code.

John wrote ADOdb so he is looking to speed it up.

> IIRC, PHP 5 adds a cache to reduce the lookup overhead for
> call_user_function; you probably won't be able to get it to go much
> faster than it does already.

I'm not seeing any bottleneck there John. My bottleneck seems to come 
with the result set, rather than the call, but none of it is causing a 
problem yet. (Running on PHP5 of cause)

-- 
Lester Caine
-----------------------------
L.S.Caine Electronic Services

---

## #11492 — Andi Gutmans — 2004-07-22T23:34:45+00:00

URL: https://externals.io/message/11462#11492 · In reply to: #11462

Check out zend_call_function(). It allows you to cache the function lookup 
in the fci_cache parameter.

Andi

At 07:17 PM 7/22/2004 +0800, John Lim wrote:
>Hi,
>
>I am using call_user_function_ex() to call mysql_fetch_array, ocifetchinto,
>etc.
>
>  error = call_user_function_ex(EG(function_table),
>       NULL,
>       &function_name_zval,
>       &retval, 2,  &params[1], 0, `NULL` TSRMLS_CC);
>
>This is not giving me the performance I am looking for because the Zend
>Engine
>still has to  search for the function to call. Is there any way to get  a
>function
>pointer to mysql_fetch_array/ocifetchinto etc., and call the function
>directly ?
>
>Thanks in advance.

---

## #11499 — Lester Caine — 2004-07-23T07:08:00+00:00

URL: https://externals.io/message/11462#11499 · In reply to: #11492

Andi Gutmans wrote:

> Check out zend_call_function(). It allows you to cache the function 
> lookup in the fci_cache parameter.

Where is the best place to find zend_call_function details, nothing in 
the manual and google gives some spurious results.

-- 
Lester Caine
-----------------------------
L.S.Caine Electronic Services

---

## #11500 — Wez Furlong — 2004-07-23T08:08:13+00:00

URL: https://externals.io/message/11462#11500 · In reply to: #11499

Use the source, Luke.


> Andi Gutmans wrote:
> 
> > […]
> 
> Where is the best place to find zend_call_function details, nothing in
> the manual and google gives some spurious results.
> 
> 
> 
> --
> Lester Caine
> -----------------------------
> L.S.Caine Electronic Services

---

## #11504 — Andrey Hristov — 2004-07-23T08:34:30+00:00

URL: https://externals.io/message/11462#11504 · In reply to: #11499

You can find some usage of this function in ext/standard/array.c

hth,
andrey

Quoting Lester Caine <lester@lsces.co.uk>:

> Andi Gutmans wrote:
>
> > […]
>
> Where is the best place to find zend_call_function details, nothing in
> the manual and google gives some spurious results.
>
> --
> Lester Caine
> -----------------------------
> L.S.Caine Electronic Services

---

## #11505 — Lester Caine — 2004-07-23T09:05:32+00:00

URL: https://externals.io/message/11462#11505 · In reply to: #11504

Andrey Hristov wrote:

> You can find some usage of this function in ext/standard/array.c

> > […]

Ta - but I'll leave this to John :)
It's a level below where I can usefully help at the moment, but since 
John can't support all the database types, I may need to delve deeper in 
the future. At present I don't have the tools in place to do my own 
builds of PHP, so I'll stick to areas where I can ;)

-- 
Lester Caine
-----------------------------
L.S.Caine Electronic Services
