Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
joanhey opened this issue Oct 6, 2022 · 5 comments
Open

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

joanhey opened this issue Oct 6, 2022 · 5 comments

Comments

@joanhey
Copy link

joanhey commented Oct 6, 2022

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

@soulteary
Copy link
Owner

Hi @joanhey 👋

ngx-php is a good project, and writing some articles about it may be of value to most people, but for now, it may be a bit late.

Its threshold for getting started depends on the perfection of the ecosystem, including migration tools, debug/trace tools, pre-built images, etc.

I think this is more feasible if the project author gets involved. Maybe you can try to ask the project author, is there a plan for this? Looking forward to hearing your suggestions.

Regards

@joanhey
Copy link
Author

joanhey commented Oct 6, 2022

It's an open source project, and It's up to everyone to help.
Like I did adding OPcache and to the Techempower benchmark.

Now I'm creating a class, to use almost any modern php app without any change (without migrations).
I did it also for workerman.

The debug/trace tools work the same than with normal php.

Pre-built images are good for testing, but not for production.
In production you want your modules: brotli, stream, .... and normally you create your images.
So perhaps will be more interesting to add in nginx-extras, like another module.

And we need to show realistic benchmarks, and show ways to better code in async php.

@joanhey
Copy link
Author

joanhey commented Oct 10, 2022

The ecosystem is OK.

But the solutions need to go in the right direction.

All async PHP solutions (ngx-php, workerman, amp, react, ...) are persistent apps.
The same than in Go, Nodejs, Rust, ...

The problem with the classes, that are already defined and can't be redeclared, it's the same that happen with nodejs, ...
Also you can't redeclare a constant in that languages.

Separate the classes, like you had at the beginning of your article (template and whisper), and in the index.php use an include_once() for that clases.
So only the first time they will be loaded. And the problem with redeclaring will be gone.

The problem is NOT with global or static variables. It's with redeclaring constants and classes.

There are better solutions, that we will show later, but this is very simple.

@joanhey
Copy link
Author

joanhey commented Oct 10, 2022

In reality you can do the same with the constants and creation of the dir.

config.php

<?php
date_default_timezone_set('Asia/shanghai');

define('TEMPLATE_DIR', '/usr/share/nginx/html/templates');
define('DATA_DIR', '/usr/share/nginx/html/data');
define('WHISPER_PER_PAGE', 5);
define('ERROR_IS_EMPTY', '内容不能为空');

if (defined('DATA_DIR')) {
    if (!file_exists(DATA_DIR)) {
        mkdir(DATA_DIR);
    }
} else {
    echo "需要定义数据目录";
    exit;
}

Now the index.php is so:

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

new Whisper();

Also change the include() to include_once() in the template class.

This solution will work with ngx-php and php-fpm or apache mod_php. And fixed the 2 problems.
Later we will see better solutions.

@joanhey
Copy link
Author

joanhey commented Oct 10, 2022

All modern PHP frameworks and apps, use a front controller normally in the index.php
Where they have the autoload and the call to one function that initiate the app.

So you will not need to include the files, and will be ready for ngx-php.

example:

<?php
require_once  __DIR__."/vendor/autoload.php";

$app = new Slim\App();
$app->run();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants