This model is memory intensive and does not scale well.
A more accurate comparison would be something like Nginx + PHP+FPM or even HipHop VM for PHP.
If you're only measuring stick is "Upload your scripts and run, BAM!" then it's no real argument. But if you're at the scale of having professional systems engineers and scaling to millions of users then deployment isn't an issue as you have your processes running smoothly.
If you can deploy the same set up 10,000 times easily, it doesn't matter that the initial set up took you 2 hours vs. 1 hour.
Software is infinitely reproducible. The effective deployment cost then becomes 0.
Essentially, at scale, you are no longer running Apache + mod_php.
If you had 10,000 web servers, are you telling me its difficult to create a script that will automatically pull files from a centralised network store?
In the above case, that's how I would set up and its trivial.
(ns nurblizer.core
(:gen-class)
(:use compojure.core)
(:require
[clojure.string :as str]
[clostache.render :as clostache]
[ring.adapter.jetty :only run-jetty]
[compojure.handler :only site]))
;; main nurble stuff
(def nouns
(->> (-> (slurp (clojure.java.io/resource "nouns.txt")) ; read in nouns.txt
(str/split #"\n")) ; split by line
(map (comp str/trim str/upper-case)) ; feed the lines through upper-case and trim
set)) ; transform into a set
(def nurble-replacement-text "<span class=\"nurble\">nurble</span>")
(defn nurble-word [word]
(get nouns (str/upper-case word) nurble-replacement-text)) ; return word if word in set else nurble
(defn nurble [text]
(str/replace text #"\n|\w+" #(case % ; using anon func literal, switch on argument
"\n" "<br>" ; when arg is newline replace with br
(nurble-word %)))) ; otherwise nurble the argument (a word)
;; webserver stuff
(defn read-template [template-file]
(slurp (clojure.java.io/resource (str "templates/" template-file ".mustache"))))
(defn render
([template-file params]
(clostache/render (read-template template-file) params
{:_header (read-template "_header")
:_footer (read-template "_footer") })))
(defroutes main-routes
(GET "/" [] (render "index" {}))
(POST "/nurble" [text] (render "nurble" {:text (nurble text)})))
(defn -main []
(run-jetty (site main-routes) {:port 9000}))
The result is the same but the approach is different: build a set of uppercase nouns, define how each word in the text is handled, and do a single string replacement pass over the text to produce the output. Doing things like tokenizing the text and processing it as a seq or keeping the nouns lower case and producing upper case output are easy but seem like unnecessary complications so I left them out.Note: In the grand tradition of the exercise, the webserver stuff is untested. I did repl-check the nurble part but was too lazy to set up a project.clj and have leiningen pull in the webserver deps.
What do you mean by standardizedPHP was quite popular in the past, and serves about 35% of the web traffic(wikipedia and facebook alone would constitute a significant amount).
I don't know about you, but my requirements are to get the job done reasonably, not "get the job done by copying a script on a cheap-ass shared hosting and you can't install any extra library. lol".
Problem with PHP (for me) is that you gotta install Apache to make it work.
PHP Notice: Undefined variable: nouns in nurble.php on line 12
PHP Notice: Undefined variable: nouns in nurble.php on line 12
PHP Notice: Undefined variable: nouns in nurble.php on line 12
PHP Notice: Undefined variable: nouns in nurble.php on line 12
PHP Notice: Undefined variable: nouns in nurble.php on line 12
;-)(Also: check out explode() instead of preg_split() and with a simple pattern like this, str_ireplace might be faster, as might be searching for the word in the whole text file instead of converting it into an array.)
is apache not cool anymore? i've done some pretty beast installations and apache handled them just fine.