Giter Club home page Giter Club logo

mark's Introduction

Mark is a high performance API micro framework based on FastRoute and workerman helps you quickly write APIs with php. It is so simple that the core codes is only about 200 lines.

Install

It's recommended that you use Composer to install Mark.

composer require mark-php/mark

Usage

start.php

<?php
use Mark\App;

require 'vendor/autoload.php';

$api = new App('http://0.0.0.0:3000');

$api->count = 4; // process count

$api->any('/', function ($requst) {
    return 'Hello world';
});

$api->get('/hello/{name}', function ($requst, $name) {
    return "Hello $name";
});

$api->post('/user/create', function ($requst) {
    return json_encode(['code'=>0 ,'message' => 'ok']);
});

$api->start();

Run command php start.php start -d

Going to http://127.0.0.1:3000/hello/world will now display "Hello world".

Benchmark

https://github.com/the-benchmarker/web-frameworks#results

Available commands

php start.php restart -d
php start.php stop
php start.php status
php start.php connections

License

The Mark Framework is licensed under the MIT license. See License File for more information.

mark's People

Contributors

passwalls avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mark's Issues

(Doubt)

how can I call a synchronous function or wait for a response using mark?
my current code is as follows (is messy due to attempts)
I would like to know how do I "testsql" send data for the first return
(sorry for opening a doubt here but I had already given up looking for her)

<?php
use Mark\App;
use Workerman\Connection\AsyncTcpConnection;

require 'vendor/autoload.php';
//---------------------API -------------------//
$api = new App('http://0.0.0.0:3030');
$api->count = 4;
$api->any('/', function ($requst) {
    return testesql();
});

function testesql()
{
    $sql_connection = new AsyncTcpConnection('Text://127.0.0.1:1234');
    $sql_connection->connect();
    $sql_connection->send('SELECT titulo FROM perguntas WHERE id = 2');
    $teste = '';
    $sql_connection->onMessage = function($sql_connection, $sql_result) use ($teste)
    {
        var_dump($sql_result);
        return ($sql_result);
    };
    var_dump("me chamam primeiro");
    return json_decode($teste);
}
$api->start();

Recommended ORM

Hi @passwalls

We're targeting a framework with an ORM (MySQL, Redis) and support for Json, Protobuf, and REST/Websocket.

Only building micro services.

Mark seems a bit stripped. We are not sure how to proceed. Do we use external libraries for ORM? Recommend something?

What do you recommend?

Benchmark with Apache Benchmark

Benchmark with ab is not working

Benchmarking 127.0.0.1 (be patient)...apr_pollset_poll: The timeout specified has expired (70007)

Sorry for this

Sorry for this but this is NOT a framework at all.
Is just a wrapper around workerman for 6 methods.

I was expecting more honestly.

Dont want to hurt anyones feelings with this either.

Xdebug support

hi! Is Xdebug supposed to work?

I can debug other PHP applications including CLI ones with XDebug on Windows 10 but mark doesn't seem to work.

Example code:

<?php
require 'vendor/autoload.php';
use Mark\App;
$api = new App('http://0.0.0.0:3000'); // Xdebug breakpoint here works
$api->count = 1;
$api->any('/', function ($requst) {
    return 'Hello world'; // Xdebug breakpoint here doesn't work
});
$api->start();

Accessing post request payload

Hi, thanks for your work.
I'm not a workerman user so my apologies for such a simple question.
In your post example, $requst returns a huge object: how to retrieve the body payload? I've already looked at workerman docs but it's not clear either.
I noticed mark is #1 in benchmark at the moment so I want to benchmark it with a slightly different json rest test (I'm pretty impressed in their test it overclasses go, which can be compiled).
Thanks.

Regex?

How complex can regex get in the route vars?

Nested routes?

Will there be an ability to make nested routes?
example:

$api->with('/book/{id}', function ($request) {
    $api->any('/read', function ($requst) {
        return 'Hello world';
    });
    $api->any('/delete', function ($requst) {
        return 'Delete book stub';
    });
});

reduced speed when running a server with openresty

Hi, doing direct benchmarks on the machine with Mark the speed is remarkable, but if I pass my connection through an api gateway with openresty doing the benchmark the speed drops a lot and I would like to understand how to improve it.

Bind to hostname

Hi,
I'm trying to bind the app to hostname, so I can have two instances of the app on the same IP and same port, but on different hostnames.
Service starts ok, but when I visit the domain I get Connection Refused by browser. Binding to IP works fine. How can I debug, or is it possible at all?
Thanks

There is only GET and POST methods available?

I've seen just get and post methods, how about put/patch/delete?

public function get($path, $callback);
public function post($path, $callback);
public function any($path, $callback);

From nikic/FastRoute docs:

For the GET, POST, PUT, PATCH, DELETE and HEAD request methods shortcut methods are available.

Is it just a missing implementation in marks base methods?

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.