<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## FFI PHP Foreign Function Interface (FFI) 是 PHP 7.4 引入的一個新特性,它允許 PHP 代碼調用 C 語言的庫函數,而無需編寫額外的擴展。 FFI 使得 PHP 能夠直接與其他編程語言編寫的庫進行交互,從而擴展其功能。這使得PHP開發人員能夠輕松利用現有的C庫,如加密算法、操作系統API等,從而實現以前只能在其他低級語言中完成的任務。 ## 主要用途 * **調用系統級庫**:PHP FFI 可以用于調用系統級的 C 庫,如 libc(標準 C 庫),以執行底層系統操作,如內存管理、文件操作等。 * **使用高性能庫**:PHP FFI 可以讓你使用 C/C++ 編寫的高性能庫,如圖像處理、加密、數據庫等,從而提高 PHP 應用程序的性能。 * **避免編寫擴展**:在以前,如果你想在 PHP 中使用某個 C/C++ 庫,你通常需要編寫一個 PHP 擴展。現在,使用 FFI,你可以直接調用這些庫,而無需編寫和維護擴展。 ## 兩種啟用方式 * 編譯安裝PHP的時候開啟`FFI`擴展`--with-ffi` * 已經安裝PHP,通過擴展來編譯安裝`FFI`擴展 ### 編譯開啟`FFI` ```ts ./configure --prefix=/usr/local/php-8.3.1 --with-ffi ``` ### 編譯擴展開啟`FFI` 下載 ```ts wget https://www.php.net/distributions/php-8.3.1.tar.gz ``` 解壓 ``` tar -zxvf php-8.3.1.tar.gz cd php-8.3.1/ cd ext/ffi/ ls config.m4 config.w32 CREDITS ffi_arginfo.h ffi.c ffi.g ffi_parser.c ffi.stub.php php_ffi.h tests ``` 生成 `./configure` 配置文件 ```ts /usr/local/php-8.3.1/bin/phpize Configuring for: PHP Api Version: 20230831 Zend Module Api No: 20230831 Zend Extension Api No: 420230831 ``` 指定配置文件 ```ts sudo ./configure --with-php-config=/usr/local/php-8.3.1/bin/php-config ``` 編譯 ```ts sudo make -j4 PATH="$PATH:/sbin" ldconfig -n /home/www/build/php-8.3.1/ext/ffi/modules ---------------------------------------------------------------------- Libraries have been installed in: /home/www/build/php-8.3.1/ext/ffi/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Build complete. Don't forget to run 'make test'. ``` 安裝 ```ts sudo make install Installing shared extensions: /usr/local/php-8.3.1/lib/php/extensions/no-debug-non-zts-20230831/ ``` php.ini 開啟擴展 ```ts extension=ffi ffi.enable=true ``` 檢查是否安裝成功 ```ts /usr/local/php-8.3.1/bin/php -m | grep FFI FFI ``` ## 基礎使用 ``` <?php /** * @desc 基礎 FFI 用法 * @author Tinywan(ShaoBo Wan) */ declare(strict_types=1); // 創建 FFI 對象,加載 libc 和輸出函數 printf() $ffi = FFI::cdef( "int printf(const char *format, ...);", // 這是普遍的 C 聲明 "libc.so.6"); // call C's printf() $ffi->printf("Hello %s!\n", "world"); ``` 執行以上示例會輸出: ``` /usr/local/php-8.3.1/bin/php ffi.php Hello world! ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看