PHP: Using Extensions - Manual
PHP  
downloads | documentation | faq | getting help | | php.net sites | links 
search for in the  
previousCreating ExtensionsTroubleshootingnext
Last updated: Tue, 09 Jul 2002
view this page in Printer friendly version | English | Brazilian Portuguese | Czech | Dutch | Finnish | French | German | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Turkish

Fejezet 30. Using Extensions

Depending on the build process you selected, you should either end up with a new PHP binary to be linked into your Web server (or run as CGI), or with an .so (shared object) file. If you compiled the example file first_module.c as a shared object, your result file should be first_module.so. To use it, you first have to copy it to a place from which it's accessible to PHP. For a simple test procedure, you can copy it to your htdocs directory and try it with the source in 30-1 P�lda. If you compiled it into the PHP binary, omit the call to dl(), as the module's functionality is instantly available to your scripts.

Figyelem

For security reasons, you should not put your dynamic modules into publicly accessible directories. Even though it can be done and it simplifies testing, you should put them into a separate directory in production environments.

P�lda 30-1. A test file for first_module.so.

<?php
    
// remove next comment if necessary
// dl("first_module.so"); 

$param = 2;
$return = first_module($param);

print("We sent '$param' and got '$return'");

?>

Calling this PHP file in your Web browser should give you the output shown in 30-1 �bra.

�bra 30-1. Output of first_module.php.

If required, the dynamic loadable module is loaded by calling the dl() function. This function looks for the specified shared object, loads it, and makes its functions available to PHP. The module exports the function first_module(), which accepts a single parameter, converts it to an integer, and returns the result of the conversion.

If you've gotten this far, congratulations! You just built your first extension to PHP.

User Contributed Notes
Using Extensions
add a note about notes

27-Feb-2002 10:40

WIN32 Note: Don't be fooled like I was. The extension dll is not all there
is to the extension. There are often supporting DLLs that must be in your
path. If not PHP goes away and doesn't come back. If you are like me and
don't like filling the system32 directory with 20 something DLLs to get
one extension to work, then add an entry to your system path that points
at your php\dll directory. That way you have all the php related DLLs in
the same place and when the extension needs a supporting DLL windows can
find it. Windows will have to be restarted for IIS to pick up the system
path change. 
:-) <>< Ryan

MrHuge
13-May-2002 10:22

[quote]
Windows will have to be restarted for IIS to pick up the system
path change. 
[/quote]

You can also just restart the internet services by command-prompt:
net stop iisadmin /yes
net start w3svc
net start <any other iisadmin dependent service you use>

The first command will stop the IIS Admin services and its dependent
services (w3svc, msftpsvc, etc), and the second one will start the WWW
Service.

In this way IIS will pick up the system path change also.

add a note about notes
previousCreating ExtensionsTroubleshootingnext
Last updated: Tue, 09 Jul 2002
show source | credits | stats | mirror sites:  
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Fri Jul 12 08:19:06 2002 CEST