MacOS下使用zephir进行php扩展开发

开发工具/依赖

  1. PHP 安装包(这里使用php7.2)
  2. zephir解析器c扩展
  3. zephir开发工具
  4. phpStorm

mac下PHP安装

brew安装

brew install php72

安装成功后,/usr/local/Cellar目录下会存在php/${version}目录,添加目录到环境变量,由于MaxOS系统默认安装php版本过低且无法覆盖该文件,所以我给新安装的php版本可执行程序设置别名,可添加到~/.bashrc下

#添加php72别名
alias php7=/usr/local/Cellar/php/7.2.12_2/bin/php
alias php7-config=/usr/local/Cellar/php/7.2.12_2/bin/php-config
alias php7-ize=/usr/local/Cellar/php/7.2.12_2/bin/phpize
alias php7-fpm=/usr/local/opt/php/sbin/php-fpm
alias pecl7=/usr/local/Cellar/php/7.2.12_2/bin/pecl

如果想控制php-fpm,执行命令

brew services php start|stop|restart

mac下zephir c扩展安装

由于zephir扩展不在pecl上,并且brew已经取消php扩展安装方式,所以这里我们采用源码安装

git clone git://github.com/phalcon/php-zephir-parser.git
cd php-zephir-parser
php7-ize
./configure
make
sudo make install

添加如下内容到/usr/local/etc/php/7.2/php.ini

[Zephir Parser]
extension=zephir_parser.so

验证是否安装成功

php -m
...
Zephir Parser
...

zephir phar开发工具安装

下载最新zephir.phar,然后移动到自己可以找到的位置下,例如~/

➜  dotm2 git:(master) ✗ php7 ~/zephir.phar 
 _____              __    _
/__  /  ___  ____  / /_  (_)____
  / /  / _ \/ __ \/ __ \/ / ___/
 / /__/  __/ /_/ / / / / / /
/____/\___/ .___/_/ /_/_/_/
         /_/

Zephir 0.11.8 by Andres Gutierrez and Serghei Iakovlev (4495e75)

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --dumpversion     Print the Zephir version — and don't do anything else
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  api        Generates a HTML API based on the classes exposed in the extension
  build      Generates/Compiles/Installs a Zephir extension
  clean      Cleans any object files created by the extension
  compile    Compile a Zephir extension
  fullclean  Cleans any object files created by the extension (including files generated by phpize)
  generate   Generates C code from the Z
JsonRPC 2.0 Client and Server ============================= 轻量级 Json-RPC 2.0 客户端和服务端的php扩展,基于 multi_curl epoll的并发客户端,依据[jsonrpc](http://www.jsonrpc.org/)协议规范。 服务端: $server = new Jsonrpc_Server(); // style one function variable $add1 = function($a, $b){     return $a   $b; }; $server->register('addition1', $add1); // style two function string function add2($a, $b){   return $a   $b; } $server->register('addition2', 'add2'); // style three function closure $server->register('addition3', function ($a, $b) {     return $a   $b; }); //style four class method string class A  {   static public function add($a, $b)   {     return $a   $b;   } } $server->register('addition4', 'A::add'); echo $server->execute(); //output >>> //{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}} 客户端: $client = new Jsonrpc_Client(1); $client->call('http://localhost/server.php', 'addition1', array(3,5)); $client->call('http://localhost/server.php', 'addition2', array(10,20)); $client->call('http://localhost/server.php', 'addition3', array(2,8)); $client->call('http://localhost/server.php', 'addition4', array(6,15)); /* ... */ $result = $client->execute(); var_dump($result); //output >>> /* array(2) {   [0]=>   array(3) {     ["jsonrpc"]=>     string(3) "2.0"     ["id"]=>     int(110507766)     ["result"]=>     int(8)   }   [1]=>   array(3) {     ["jsonrpc"]=>     string(3) "2.0"     ["id"]=>     int(1559316299)     ["result"]=>     int(30)   }   ... } */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值