4 ms·
Interesting article, except that the examples don't line up exactly. For example, in PHP it's trivial to store the file contents in a var and refer to that over
by Jemaclus 14y ago
Interesting article, except that the examples don't line up exactly. For example, in PHP it's trivial to store the file contents in a var and refer to that over and over (as OP does in Ruby), but instead he chooses to read from the file over and over again and then calls that a shortcoming of PHP vs Ruby when that's purely an implementation decision.
Ruby is clean (but I dislike the stack), and Python looks good, but ye gads is Closure ugly... Uglier than PHP, even.
My favorite part about PHP is how easy it is to get a simple Nurble-like app up and running... but that's just me.
- jared314 14y agoYou could submit a pull request to make his examples better. https://github.com/adambard/nurblizer-php https://github.com/adambard/nurblizer-php https://github.com/adambard/Nurblizer https://github.com/adambard/Nurblizer https://github.com/adambard/py-nurblizer https://github.com/adambard/py-nurblizer https://github.com/adambard/nurblizer-clj https://github.com/adambard/nurblizer-clj
- adambard 14y agoPlease do, I'll update and edit as appropriate. I wasn't aware a trivial way existed of storing a persistent variable in PHP between existed. I bet I'll feel dumb when I find out what it is, though.
- cheald 14y agoYou can do it with APC, but beyond that, no, your solution is the PHP way to do it.
- degroat 14y agoI think his point was just that you could hard-code your list of words into the code. It would be ugly, but it would work.
- pan69 14y agoIsn't that the same as loading them from file on each request?
- cheald 14y agoNo, because you don't have additional IO overhead.
- pan69 14y agoI think that overhead would be negligible, especially if the other examples are all based on micro-frameworks (i.e. loads of files). Premature optimisation is the root of all evil, right?
- cheald 14y agoDisk IO is a massive problem at scale. This obviously isn't "at scale", so it works fine here, but avoiding hitting the disk (edit: any slow IO, really) is Performance 101.
- lmcnearney 14y agoYou would also want to install an opcode cache like APC, XCache, etc. That way the code is only compiled on the first page load. http://en.wikipedia.org/wiki/List_of_PHP_accelerators http://en.wikipedia.org/wiki/List_of_PHP_accelerators
- teraflop 14y agoOK, I'll bite: how would you store the array of words in memory across requests in PHP? As far as I'm aware, the runtime deliberately doesn't provide a way to do that. The closest you could get is to store it in $_SESSION, but that's per-user rather than global, and it still has to read the data from your session handler. Which by default just uses flat files, so we're no better off than we started.
- deleted 14y ago[deleted]
- spoiler 14y ago... And that is something exclusive to PHP?
- jamesmoss 14y agoThe APC opcode cache extension also has a user cache which has an API similar to memcache but a bit faster since it's using shared memory and not going over the network. It's shared between all visitors across all requests. http://php.net/manual/en/book.apc.php http://php.net/manual/en/book.apc.php
- francispelland 14y agoAPC. It comes as part of the official package as of 5.2.