Novell is now a part of Micro Focus

If I write a PHP Shared Object (SO)...

Articles and Tips: qna

01 Feb 2003


Q.

If I write a PHP Shared Object (SO) extension that calls into LibC, does my SO get terminated/unloaded when the script finishes? In which case, what happens to my threads? Can I pick them up on next execution, or will LibC just gracefully close them?

If the above is true, is there a preferred method whereby my PHP SO can call into a "TSR" NLM each time the script runs? The problem I can see immediately is that the SO has to publish its exported functions, which means any change in the "TSR" NLM means a recompile of the SO.

Ideally, is there a way of keeping an extension loaded as a "TSR" to preserve my contexts, etc.?

A.

You can write your PHP extension with LibC and you should do so. Avoid using CLIB because PHPLIB.NLM itself is based in LIBC. File operations especially can cause trouble if you call CLIB APIs from your PHP extension.

A PHP extension itself only supports functionality, not the execution itself. Execution is controlled by the PHP engine itself. If, for some reason, you need separate threads, you must make sure that they terminate before execution is given back to the PHP engine.

The PHP extension itself is loaded by PHPLIB.NLM and is present in memory. This is done via dlopen...() API's. PHPLIB is loaded by Apache. If you load Apache in a protected address space, PHPLIB and all extensions are unloaded as soon as Apache is unloaded. If you load APACHE in the OS address space you need to unload all PHP-related modules manually.

Your extension normally needs to export only one symbol to work with PHP: get_module.

* Originally published in Novell AppNotes


Disclaimer

The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.

© Copyright Micro Focus or one of its affiliates