zephir implements PHP encapsulation into C language extension files so implements a simple case of demo [Rookie Level Tutorial]

  1. Install from github zephir.phar Latest URL https://github.com/zephir-lang/zephir/releases

  2. Rename the file zephir.phar to zephir and place it in the /bin directory

  3. Check if installed

    zephir help
    
  4. Install zephir_parser

    pecl install zephir_parser
    

    Add extension to php.ini. Reload

    extension=zephir_parser.so
    
  5. Execute initialization

    zephir init  app    //  app为命名空间
    
  6. Enter the app directory and there are files config.json, ext directory, app directory

  7. Write a simple PHP case

    namespace App;
    
    class MyClass
    {
        public static function sayHello()
        {
            return "Hello from Zephir!";
        }
    }
    
  8. Execute build packaging and wait for packaging to the ext directory

    zephir build 
    

    Results of the

    Preparing for PHP compilation...
     Preparing configuration file...
     Compiling...
     Zephir version has changed, use "zephir fullclean" to perform a full clean of the project
     Installing...
    
     Extension installed.
     Add "extension=app.so" to your php.ini
    ! [NOTE] Don't forget to restart your web server 
    
  9. Enter ext and execute install to install into the PHP environment so, and restart the PHP service

  10. Create a new PHP file

    echo  App\MyClass::sayHello();
    
  11. Display Hello from Zephir! normally.

Guess you like

Origin blog.csdn.net/abc564643122/article/details/134765427