Live data from Hacker News

Pux – High Performance Router for PHP

github.com

41–50 of 58 posts

Re: Pux – High Performance Router for PHP

#41
post #36
post #33

Earlier quoted context omitted.

If you're building a web application in PHP, then symfony is a huge improvement over naked php files or rolling your own bootstrapped system. Right out of the box it addresses concerns of security, user management, routing, persistence, and myriads of the other basic needs of a web system. Packages for many common components are already built, meaning you can get sophisticated functionality working quickly. It is mod…

Look at the php.net website source code. Another example could be the Wordpress source code. It's not handsome code, but it just works. Things like fat (either slim) frameworks should be memory resident (java or similar), not reloaded from scratch at each web request, it just won't never perform on big sites. Alternatively, if you need to deal with bigger applications, or massive traffic, you can build some kind of b…

Any "big site" will use an opcode cacher like XCache or APC to avoid reloading .php files from disk on every request.

Re: Pux – High Performance Router for PHP

#42
post #30

My personal opinion is that either no symfony and no pux should exist. There's no need to reinvent frameworks in PHP as PHP is the framework already. There's no need to reinvent templating in PHP as PHP is the templating already. If you require different productivity from a language just don't stick on PHP and make the right choice by using the most appropriate language for you. There's plenty out there. PHP is great…

Exactly. You don't need a 'router' when you have the filesystem and mod_rewrite.

What about when you are deploying with PHP-FPM or HipHopVM? A native routing component separates your application from your application server.

Re: Pux – High Performance Router for PHP

#43
First of all, for your information, the benchmark code and details are already there: https://github.com/c9s/router-benchmark sorry I forgot to put the link. :p

We firstly tested the pure dispatching benchmark by a simple benchmark tool. (without ab), code is here.

https://github.com/c9s/router-benchmark/blob/master/code/dis...

Tests including klein, ham, aura, symfony/routing. This tests pure dispatching speed, so the benchmark does not includes cache.

The dispatching benchmark result is here:

https://github.com/c9s/router-benchmark/blob/master/code/dis...

The benchmark with apache is just to show the comparison result (which shares the same configurations).

Pux is basically written in C extension, which reduces the overhead to load classes from PHP files. Also it does a different strategy on route dispatching. to compare the routes as fast as possible, pux uses indexed array to store the route pattern, pcre flag. (In PHP internals, zend_hash_index_find is faster than zend_hash_find)

it's not just iterating all routes in a big loop like Symfony.

Re: Pux – High Performance Router for PHP

#45

The problem with this is you can accomplish essentially the same thing in userland if you know how to write a good "compiled regex" ... Calling the pcre functions in C land gains you very little. An extension is totally unnecessary.

I don't think so.

Using pure PHP, you need to load a lot of class files. and function calls, method calls, hash find are pretty slow in pure PHP.

- First of all, while using C extension, you don't need to reload these php class files again and again. it reduces the class loading overhead.

- Seconds, looping and string comparison is pretty fast in C. it's because in pure PHP, it duplicates the string when calling functions/methods in the runtime.

- Third, there are a lot of spaces to optimize the code in C rather than in pure php.

- Last, pure PHP consumes a lot of memory, but in C extension, the memory footprint is pretty small.

Re: Pux – High Performance Router for PHP

#46
post #24
post #9

Earlier quoted context omitted.

Probably by the php extension in c :) I would think that phalcon router will be faster too.

The README says that the c extension is only 1.5x-2x faster than the pure PHP Pux. So this doesn't explain 50x faster.

1.5x-2x different is from apache.

the pure dispatching speed can be 10+x faster with C extension.

Re: Pux – High Performance Router for PHP

#47
post #36

Earlier quoted context omitted.

Look at the php.net website source code. Another example could be the Wordpress source code. It's not handsome code, but it just works. Things like fat (either slim) frameworks should be memory resident (java or similar), not reloaded from scratch at each web request, it just won't never perform on big sites. Alternatively, if you need to deal with bigger applications, or massive traffic, you can build some kind of b…

Any "big site" will use an opcode cacher like XCache or APC to avoid reloading .php files from disk on every request.

Honest question: while I know that's true (I was using APC, now using Zend Opcode or whatever the replacement in PHP 5.5 is whose name escapes me at the moment), it seems to me that there's still going to be a performance penalty incurred. The PHP may be all compiled to bytecode at that point and the bytecode may be 100% memory resident, but you're running through all the initialization routines for the framework on each and every page hit.

"Pure" PHP is a pretty fast language when benchmarked, but PHP frameworks tend to benchmark poorly, and I've always assumed that the overhead incurred by PHP's execution model is the culprit -- essentially, PHP was written with assumptions about How Dynamic Web Sites Work that made sense in the late '90s but really suck when every request is hitting a front controller and being dispatched through a router. Is this not the case?

Re: Pux – High Performance Router for PHP

#49
post #43

First of all, for your information, the benchmark code and details are already there: https://github.com/c9s/router-benchmark sorry I forgot to put the link. :p We firstly tested the pure dispatching benchmark by a simple benchmark tool. (without ab), code is here. https://github.com/c9s/router-benchmark/blob/master/code/dis... Tests including klein, ham, aura, symfony/routing. This tests pure dispatching speed, so t…

> it's not just iterating all routes in a big loop like Symfony.

Well, that happens if you turn off the cache. Otherwise, Symfony actually compiles the routes into something resembling a prefix tree.

Re: Pux – High Performance Router for PHP

#50
post #5

> Pux tries not to consume computation time to build all routes dynamically (like Symfony/Routing). Instead, Pux compiles your routes to plain PHP array for caching, the compiled routes can be loaded from cache very fast. symfony/routing compiles routes only once to PHP code ([1]), and then that generated code is used for matching all subsequent requests. (There are multiple route matchers, but the default one works…

> How is this achieved ?

By not utilizing the symfony/routing cache at all.

Sorry to say, this is a meaningless test.

Post reply on HN