Giter VIP home page Giter VIP logo

yarf-framework's Introduction

Yarf框架

接口端框架(RPC),专注于数据提供。框架基于yaf+yar(快速请求,并发处理)开发,可实现不同的请求处理

####功能实现

  • 识别Post/Get接口请求
  • 实现Restful请求
  • 实现Yar单请求以及并发请求
  • 接口集成ORM(填补yaf短板)
  • 集成Cache层

注:同一url可以实现post/get/restful/yar请求

###框架目录

###### 组织架构如下: 
    yarf-root                                       //根目录(irpackagis这个无所谓随便起)
        |---README.md                               //帮助文档
        |---composer.json                           //固定格式文件(必须)
        |---vendor                                  //第三方类库包目录
        |---public                                  //入口目录
              |---index.php                         //入口文件
        |---app
              |---application
                    |---controllers
                    |---library
                    |---models
                    |---modules
                    |---plugins
                    |---views
                    |---Bootstrap.php
                    |---Service.php
              |---conf
                    |---app.php
                    |---application.ini
                    |---config.php

样例演示

http://192.168.8.234:7070/user/index/get为请求对象

1、Post/Get请求 示例如下:
<?php
//get请求
$url = "http://192.168.8.234:7070/user/index/get?uid=120";
$response = file_get_contents($url);
echo $response."<br>\n";

//post请求
$url = "http://192.168.8.234:7070/user/index/get";
$postArr = array('uid'=>200);
$response = curl_by_post($url,$postArr);
echo $response."<br>\n";

function curl_by_post($url,$post) {
    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
    $result=curl_exec($ch);
    curl_close($ch);
    return $result;
}
2、Restful请求 示例如下:
<?php
$url = "http://192.168.8.234:7070/user/index/get/uid/300";
$response = file_get_contents($url);
echo $response."<br>\n";

$url = "http://192.168.8.234:7070/user/index/del/uid/300";
$response = file_get_contents($url);
echo $response."<br>\n";
3、yar请求 示例如下
<?php
$params = array('uid'=>2548);
$rpcUrl = 'http://192.168.8.234:7070/user/index/get';
$client = new yar_client($rpcUrl);
$result = $client->run($params);
var_dump($result);
4、yar并发请求 示例如下:
<?php
$params = array('uid'=>2548);

Yar_Concurrent_Client::call("http://192.168.8.234:7070/user/index/get", "run", array($params), "callback");
Yar_Concurrent_Client::call("http://192.168.8.234:7070/user/index/del", "run", array($params), "callback");
Yar_Concurrent_Client::loop("callback", "error_callback"); //send the requests, 

function callback($retval, $callinfo) {
    echo $retval."\n<br>\n";
}
function error_callback($type, $error, $callinfo) {
    error_log($error);
}

yarf-framework's People

Contributors

ivan-king avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.