Git Product home page Git Product logo

soulteary / ngx-php-micro-blog Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 1.0 365 KB

Microlog example based on Nginx and Nginx module (NGX-PHP8), A high-performance implementation that does not use the combination of Nginx and PHP-FPM, which is safe and reliable.

Home Page: https://soulteary.com/2022/10/05/nginx-black-magic-low-cost-high-performance-applications-using-ngx-php-modules.html

License: Apache License 2.0

CSS 2.44% PHP 41.36% HTML 29.52% Dockerfile 18.16% Shell 8.52%
microblog nginx nginx-docker nginx-module nginx-php ngx-php php

ngx-php-micro-blog's Introduction

Nginx NGX-PHP Module Demo (MicroBlog)

English Ver / 中文教程

使用 Nginx 模块 NGX-PHP 实现的一个简单的微博应用 Demo,不依赖 PHP-FPM 等技术栈,高效、安全、可靠。

基于 Nginx 官方容器构建,基础镜像仅 12MB。

界面预览

使用方法

启动容器:

docker run --rm -it -v `pwd`/data:/usr/share/nginx/html/data:rw -p 8090:80 soulteary/ngx-php:8-microblog

或者使用 docker compose:

docker-compose -f docker-compose.ngx-php.yml up

打开浏览器:http://localhost:8090

性能测试

对比 soulteary/ngx-php:8php:8.1.10-apache-buster

soulteary/ngx-php:8

wrk -t16 -c 100 -d 30s http://127.0.0.1:8090     
Running 30s test @ http://127.0.0.1:8090
  16 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    94.01ms   15.94ms 431.01ms   81.62%
    Req/Sec    64.02     11.33   148.00     74.26%
  30715 requests in 30.09s, 65.03MB read
Requests/sec:   1020.65
Transfer/sec:      2.16MB

php:8.1.10-apache-buster (opcache.enable=1)

wrk -t16 -c 100 -d 30s http://127.0.0.1:8090     
Running 30s test @ http://127.0.0.1:8090
  16 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   132.92ms  158.49ms   1.98s    86.67%
    Req/Sec    54.38     56.83   670.00     94.88%
  22603 requests in 30.08s, 49.40MB read
  Socket errors: connect 0, read 0, write 0, timeout 112
Requests/sec:    751.53
Transfer/sec:      1.64MB

相关项目

ngx-php-micro-blog's People

Contributors

soulteary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

joanhey

ngx-php-micro-blog's Issues

Ngx-php is orders of magnitude faster than php-fpm

Hi Su Yang

I really like ngx-php, and I added OPCache to it with the help of the author.
Also I maintain almost all php frameworks in the Techempower benchmark.

But hat numbers don't look correct to me. And ngx-php need more marketing.

I will try to send issues and PRs to explain the correct use of ngx-php.

As you seem to be a good communicator, could you explain it in Chinese.
I will try the same in English and Spanish.

Regards

Faster and more secure solution

Before

We saw, how to include all in the index.php

<?php
include_once('config.php');
include_once('template.php');
include_once('whisper.php');

new Whisper();

After

But we can load it in the nginx.conf, so we don't have any php file in the root.
And we don't need to load any php file.
Also we can place the complete file in start.php, because will load only one time, and will not be redeclaration of constants or classes.

start.php (outside of the root)

<?php
require ('config.php');
require ('template.php');
require ('whisper.php');

//or
//require  __DIR__."/vendor/autoload.php";

In the nginx.conf

....
php_ini_path /path/to/php.ini;

init_worker_by_php '
        require "path/start.php";
';

....

location  / {
	 content_by_php '
               new Whisper();
         ';
        }

Ngx-php is NOT using OPcache

Both need to use OPcache to compare it.

Apache-buster is using OPcache but ngx-php NO.
OPcache have a really big impact in PHP performance.

Apache-buster:
image

Ngx-php without Zend OPcache
image

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.