php与dubbo

By | 2020 年 2 月 14 日

系统:Red Hat 4.4.7-17 内核:2.6.32-642.el6.x86_64
PHP版本:PHP-7.0.9
swoole版本:4.0.2及以上
Redis php扩展版本: 3.1.3
Redis版本: 3.0.0
Zookeeper php扩展版本:0.5.0
Zookeeper版本:3.4.10

一、用bt服务器来开始
检查php版本,在php环境中配置扩展 redis、swoole4X。

二、Zookeeper安装

wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.6/apache-zookeeper-3.5.6.tar.gz
tar -zxvf apache-zookeeper-3.5.6.tar.gz 
cd apache-zookeeper-3.5.6
cd zookeeper-client/zookeeper-client-c/
autoreconf -if
./configure
make&&make install

三、Zookeeper php扩展安装
到pecl.php.net查询 zookeeper扩展,选择了稳定正式版

wget http://pecl.php.net/get/zookeeper-0.6.4.tgz
taz -zxvf zookeeper-0.6.4.tgz 
cd zookeeper-0.6.4
phpize
./configure --with-php-config=/www/server/php/71/bin/php-config
make&&make install
ls /www/server/php/71/lib/php/extensions/no-debug-non-zts-20160303/
opcache.a  opcache.so  redis.so  swoole.so  zookeeper.so

在bt面板修改php的配置增加
extension = zookeeper.so
重启PHP
php -m
检查有没有zookeeper组件、redis组件、swoole组件

四、尝试配置调用
1、安装composer的dubbo-php-client组件:配置阿里云的composer源

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
安装
composer require -vvv "quickj/dubbo-php-client:dev-master"

2、php安全函数禁用有时候会导致php composer异常。可以在bt的php设置中放开putenv(),pcntl_signal()两个

3、调用方法说明
https://packagist.org/packages/quickj/dubbo-php-client

五、尝试使用https://github.com/apache/dubbo-php-framework的项目
1、执行composer的安装
2、启动agent
检查启动文件以及对应的配置文件
cat agent/src/c/release/start_agent_server.sh

#!/bin/bash

log_dir="/www/wwwroot//dubbo-php-framework/agent/log/agent"

if [ ! -d $log_dir ]; then
    mkdir -p $log_dir
fi

process=$(ps aux  | grep -v "grep" | grep "release/agent_server" | wc -l) 
if [ "$process" -ne "0" ]; then
       ps aux |grep -v "grep" |grep "release/agent_server"|awk '{print $2}'|xargs kill -9
fi

cd /www/wwwroot/dubbo-php-framework/agent/src/c/release
cp agent agent_server
chmod  u+x agent_server
cur_dir=$(pwd)
$cur_dir/agent_server 600 /www/wwwroot/dubbo-php-framework/config/global/conf/fsof.ini

关注log_dir的路径,启动失败成功一定要看log
关注最后一行,启动的配置文件位置(我修正过)。打开配置文件
修改对应的zk_url_list,既你的zookeepr的服务地址,还有zklog_path,日志路径。

;php path                                                                              
      3 php = '/usr/bin/php'                                                                   
      4                                                                                        
      5 ;app's user                                                                            
      6 user = root                                                                            
      7                                                                                        
      8 [fsof_setting]                                                                         
      9 ;machine enviroment:[dev|pre|gray|pro]                                                 
     10 environment = dev                                                                      
     11                                                                                        
     12 ;in p2p mode, provider not register to registry                                        
     13 p2p_mode = false                                                                       
     14                                                                                        
     15 ;zookeeper log switch: 0.close; 1.error; 2.warn; 3.info; 4.debug                       
     16 zklog_level = 0                                                                        
     17                                                                                        
     18 ;zookeepr log path                                                                     
     19 zklog_path = '/tmp/zookeeper.log'                                                      
     20                                                                                        
     21 ;zookeeper url list                                                                    
     22 zk_url_list = http://192.168.1.33:2181                                                 
     23                                                                                        
     24 ;provider overload mode switch                                                         
     25 overload_mode = true                                                                   
     26                                                                                        
     27 ;if request wait more than waiting_time before processed, we will lost this quest, unit         is micro-second                                                                       
     28 waiting_time = 2000                                                                    
     29                                                                                        
     30 ;if overload_number requests trigger overload rule continuous, we will open loss reques        t mode                                                                                 
     31 overload_number = 5                                                                    
     32                                                                                        
     33 ;how many quest is lost before lost mode is close                                      
     34 loss_number = 20

vi agent/src/c/common/fsof_global.h 
修改
define ZOOKEEPER_HOST "192.168.1.33:2181"
define REDIS_UNIX_SOCK "/var/run/redis/redis.sock"
注意redis的sock文件位置,必须对,因为 domo的消费者是先从本地redis获取相关信息。

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
#ifndef FSOF_GLOBAL_H
#define FSOF_GLOBAL_H

#define FSOF_ROOT_NAME "/dubbo"
#define PROVIDER_NAME "/providers"
#define PROVIDER_NODE_NAME "providers"
#define CONSUMER_NAME "/consumers"
#define ROUTERS_NAME  "/routers"
#define CONFIGUREATORS_NAME "/configurators"
#define CONFIGUREATORS_NODE_NAME "configurators"
#define FSOF_REDIS_CONFIGURATOR_KEY_NAME "override"

#define ZOOKEEPER_HOST "192.168.1.33:2181"
#define DEFAULT_MAP_COUNT (10)
#define REDIS_UNIX_SOCK  "/var/run/redis/redis.sock"



struct list {
    char *value;
    struct list *next;
};

#endif

保存后,尝试启动agent
cd /www/wwwroot/dubbo-php-framework/agent/src/c/
make
cd release
./start_agent_server.sh

如果成功,你可以从redis、日志看到你的相关dubbo提供的方法等信息。没有,认真检查以上几个步骤:redis、配置文件等,注意redis文件权限,在bt的redis配置文件中修改。默认是600,可以改为644之类?另外agent的REDIS_UNIX_SOCK这个参数,修改后make不一定生效--不知道为啥。也可以修改另外一个文件在agent/src/c/service/fsof_redis.c中,修改redis的链接方式,重新make。

3、
config/app/conf/dev/provider/demo-provider.deploy 修改为实际环境值
demo/demo-consumer/server/Consumer.php中修改Logger.php值
demo/demo-provider/server/DemoServiceImpl.php修改Logger.php值


以consumer.php为例:

<?php                                                                                          
$APP_SRC_PATH = __DIR__;
//echo $_SERVER['DOCUMENT_ROOT'];
require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
$fsofApiPath = dirname(dirname(dirname($APP_SRC_PATH))).DIRECTORY_SEPARATOR.'api'.DIRECTORY_SEPARATOR.'FSOFApi.php';
//echo $fsofApiPath;die;
require_once($fsofApiPath);
FSOFApi::configure('demo-consumer', $APP_SRC_PATH);
//use log4php\Logger;
require_once($_SERVER['DOCUMENT_ROOT'].'/vendor/apache/log4php/src/main/php/Logger.php');
Logger::configure(dirname(dirname(__FILE__)).'/config/log4php.xml');
date_default_timezone_set('PRC');

//php框架调用php提供的服务
$service = '你的服务';
//echo 3;
$proxy = FSOFApi::newProxy($service, 3);
//echo 4;
$ret = $proxy->invoke("你的方法","");
echo "ret:$ret".PHP_EOL;



发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据