能否帮我讲详细一点
如果我用我php的扩展库,这个扩展库来调用动态链接库,这个扩展库是不是用exec来执行谢谢

解决方案 »

  1.   

    since you are too lazy to read the php manual,I post it here:this is an example from php manual in w32api functions.例子 1. 得到系统持续运行的时间,并把它显示在消息对话框中
    <?php
    // 定义所需的常量,来自
    // Visual Studio/Tools/Winapi/WIN32API.txt
    define("MB_OK", 0);// 加载此扩展
    dl("php_w32api.dll");// 注册 GetTickCount 函数,来自 kernel32.dll
    w32api_register_function("kernel32.dll",
                             "GetTickCount",
                             "long");// 注册 MessageBoxA 函数,来自 User32.dll
    w32api_register_function("User32.dll",
                             "MessageBoxA",
                             "long");// 取得开机时间信息
    $ticks = GetTickCount();// 转换为易于理解的文本
    $secs  = floor($ticks / 1000);
    $mins  = floor($secs / 60);
    $hours = floor($mins / 60);$str = sprintf("You have been using your computer for:".
                    "\r\n %d Milliseconds, or \r\n %d Seconds".
                    "or \r\n %d mins or\r\n %d hours %d mins.",
                    $ticks,
                    $secs,
                    $mins,
                    $hours,
                    $mins - ($hours*60));// 显示一个消息对话框,只有一个 OK 按钮和上面的开机时间文本
    MessageBoxA(NULL,
                $str,
                "Uptime Information",
                MB_OK);
    ?>
      

  2.   

    谢谢zeroleonhart, 想再问下
    1  如果动态链接库是.so的, 且php端还需要传递给动态链接库的接口
    2  在Linux系统下面, 测试下系统时间的这段代码, 出现:
       Warning: dl() [function.dl]: Dynamically loaded extensions aren't allowed when     
       running in Safe Mode in /usr/local/apache2/htdocs/design_cn/so.php on line 7   Fatal error: Call to undefined function w32api_register_function()      
       in /usr/local/apache2/htdocs/design_cn/so.php on line 10
    在php.ini中,safe_mode = On
       ....
       谢谢.
      

  3.   

    the w32api functions are available in php 4.2.0 - 4.2.3 only.
    the example in the php manual is only run under windows.
    Please read php manual first and I think it will help you much.
      

  4.   

    and I was very surprise to know you run the code under Linux.
    Do you know what w32api is????
      

  5.   

    If you want to use .so files under Linux,please read the Zend API contents in php manual.
      

  6.   

    TO: zeroleonhart
       能否帮给个在Linux下使用的例子
      

  7.   

    Creating Extensions
    We'll start with the creation of a very simple extension at first, which basically does nothing more than implement a function that returns the integer it receives as parameter. 例子 46-2 shows the source. 例子 46-2. A simple extension./* include standard header */
    #include "php.h"/* declaration of functions to be exported */
    ZEND_FUNCTION(first_module);/* compiled function list so Zend knows what's in this module */
    zend_function_entry firstmod_functions[] =
    {
        ZEND_FE(first_module, NULL)
        {NULL, NULL, NULL}
    };/* compiled module information */
    zend_module_entry firstmod_module_entry =
    {
        STANDARD_MODULE_HEADER,
        "First Module",
        firstmod_functions,
        NULL, 
        NULL, 
        NULL, 
        NULL, 
        NULL,
        NO_VERSION_YET,
        STANDARD_MODULE_PROPERTIES
    };/* implement standard "stub" routine to introduce ourselves to Zend */
    #if COMPILE_DL_FIRST_MODULE
    ZEND_GET_MODULE(firstmod)
    #endif/* implement function that is meant to be made available to PHP */
    ZEND_FUNCTION(first_module)
    {
        long parameter;    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
            return;
        }    RETURN_LONG(parameter);
    }
     
     This code contains a complete PHP module. We'll explain the source code in detail shortly, but first we'd like to discuss the build process. (This will allow the impatient to experiment before we dive into API discussions.) 注: The example source makes use of some features introduced with the Zend version used in PHP 4.1.0 and above, it won't compile with older PHP 4.0.x versions. Compiling Modules
    There are basically two ways to compile modules: 
    Use the provided "make" mechanism in the ext directory, which also allows building of dynamic loadable modules. Compile the sources manually.The first method should definitely be favored, since, as of PHP 4.0, this has been standardized into a sophisticated build process. The fact that it is so sophisticated is also its drawback, unfortunately - it's hard to understand at first. We'll provide a more detailed introduction to this later in the chapter, but first let's work with the default files. The second method is good for those who (for some reason) don't have the full PHP source tree available, don't have access to all files, or just like to juggle with their keyboard. These cases should be extremely rare, but for the sake of completeness we'll also describe this method. Compiling Using Make. To compile the sample sources using the standard mechanism, copy all their subdirectories to the ext directory of your PHP source tree. Then run buildconf, which will create an updated configure script containing appropriate options for the new extension. By default, all the sample sources are disabled, so you don't have to fear breaking your build process. After you run buildconf, configure --help shows the following additional modules: --enable-array_experiments   BOOK: Enables array experiments
      --enable-call_userland       BOOK: Enables userland module
      --enable-cross_conversion    BOOK: Enables cross-conversion module
      --enable-first_module        BOOK: Enables first module
      --enable-infoprint           BOOK: Enables infoprint module
      --enable-reference_test      BOOK: Enables reference test module
      --enable-resource_test       BOOK: Enables resource test module
      --enable-variable_creation   BOOK: Enables variable-creation module
     The module shown earlier in 例子 46-2 can be enabled with --enable-first_module or --enable-first_module=yes. Compiling Manually. To compile your modules manually, you need the following commands: 
    Action Command 
    Compiling cc -fpic -DCOMPILE_DL=1 -I/usr/local/include -I. -I.. -I../Zend -c -o <your_object_file> <your_c_file> 
    Linking cc -shared -L/usr/local/lib -rdynamic -o <your_module_file> <your_object_file(s)> 
    The command to compile the module simply instructs the compiler to generate position-independent code (-fpic shouldn't be omitted) and additionally defines the constant COMPILE_DL to tell the module code that it's compiled as a dynamically loadable module (the test module above checks for this; we'll discuss it shortly). After these options, it specifies a number of standard include paths that should be used as the minimal set to compile the source files. Note: All include paths in the example are relative to the directory ext. If you're compiling from another directory, change the pathnames accordingly. Required items are the PHP directory, the Zend directory, and (if necessary), the directory in which your module resides. The link command is also a plain vanilla command instructing linkage as a dynamic module. You can include optimization options in the compilation command, although these have been omitted in this example (but some are included in the makefile template described in an earlier section). Note: Compiling and linking manually as a static module into the PHP binary involves very long instructions and thus is not discussed here. (It's not very efficient to type all those commands.) 
      

  8.   

    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 例子 46-3. If you compiled it into the PHP binary, omit the call to dl(), as the module's functionality is instantly available to your scripts. 
    警告 
    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. 
     
    例子 46-3. 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 should output the following: We sent '2' and got '2' 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.
      

  9.   

    网上看了看zend的api,如果我要用zend,是不是需要安装zend...\
    php-src  
    php-src/ext
    php-src/main
    php-src/pear
    php-src/sapi
    api里面写的是这目录结构..刚接触php不久,被临时拽过来参与的:(
      

  10.   

    zeroleonhart(Strong Point:Algorithm) 你好久没说过中语了。美语都过12级了吧。
      

  11.   

    zeroleonhart(Strong Point:Algorithm) 你好久没说过中语了。美语都过12级了吧。--------------------------------------------------If I have met some good software companies of China,I won't speak any English.But...