Live data from Hacker News

Pux – High Performance Router for PHP

github.com

51–58 of 58 posts

Re: Pux – High Performance Router for PHP

#52
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.

Yes you can use APC, opcache or XCache to load php bytecode in runtime. but you are still calling php functions/methods or creating a lot of objects in runtime. that's the overhead.

Re: Pux – High Performance Router for PHP

#53

Not sure the performance difference, but highly recommend Flight ( http://flightphp.com/ ) as a simple router. Flight is well suited especially for building APIs. Flight has great http helper methods as well (header, json response, etc). As far as performance, I seriously doubt the bottleneck in modern applications is the router.

well, flight is not written in C extension.

have checked the code, there are a lot of magic method calls in flightphp. magic method calls are even slower than normal method call.

Re: Pux – High Performance Router for PHP

#54
post #16

If they would only first explain what the heck is "routing in PHP"... Coming from the network programming side of things, "High Performance PHP Router" sounds like a spectacular oxymoron at best :)

A news item a short while ago had the similarly phrased "router in PHP" and for a moment I thought someone had actually used PHP to write a layer-3 networking device.

Re: Pux – High Performance Router for PHP

#55
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…

Explain here:

- Pux uses simpler data structure (indexed array) to store the patterns and flags. (In PHP internals, zend_hash_index_find is faster than zend_hash_find).

- When matching routes, symfony uses a lot of function calls for each route:

https://github.com/symfony/Routing/blob/master/Matcher/UrlMa...

- Pux fetches the pattern from an indexed-array:

https://github.com/c9s/Pux/blob/master/src/Pux/Mux.php#L189

- Pux separates static routes and dynamic routes automatically, Pux uses hash table to look up static routes without looping the whole route array.

- Pux\Mux is written in C extension, method calls are faster!

- With C extension, there is no class loading overhead.

- Pux compiles routes to plain PHP array, the compiled routes can be loaded very fast. you don't need to call functions to register your routes before using it.

Re: Pux – High Performance Router for PHP

#56

Earlier quoted context omitted.

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.

Using mod_rewrite (or the nginx equivalent) with PHP-FPM will work fine. I don't see why it wouldn't work with HipHopVM either.

In over 10+ years of PHP development I have never needed a "native routing component". Call me crazy...

Re: Pux – High Performance Router for PHP

#57
post #55
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…

Explain here: - Pux uses simpler data structure (indexed array) to store the patterns and flags. (In PHP internals, zend_hash_index_find is faster than zend_hash_find). - When matching routes, symfony uses a lot of function calls for each route: https://github.com/symfony/Routing/blob/master/Matcher/UrlMa... - Pux fetches the pattern from an indexed-array: https://github.com/c9s/Pux/blob/master/src/Pux/Mux.php#L189 -…

Thanks for your answer.

> When matching routes, symfony uses a lot of function calls for each route

This is the slow UrlMatcher. The one used by default in the standard symfony edition generates code like this: https://github.com/symfony/Routing/blob/0ee25e6580bd4169c128... , and this code is used for matching instead.

Re: Pux – High Performance Router for PHP

#58
post #35
post #4

If the creators are watching, I think it'd be interesting to benchmark against the current Respect/Rest.

I thought the same thing. Here is a link for convenience. https://github.com/Respect/Rest

Also: https://github.com/Respect/benchmarks/
Post reply on HN