Sunday, February 2, 2014

Metromap Layout Engine for Interactive Browser Visualizations

Finally finished my own right-angle metromap layout for interactive browser visualizations.


For now I have it as part of Chrome Extension -- see the code which is actually a working Chrome extension at this GitHub Project Page. README in the project also explains what to feed the engine. The data structure is actually very simple.

Now I can finally finish my Rebot, properly this time.

Wednesday, January 1, 2014

PHP5 as the Current Best Mini Web Server

Quite often today ... especially in cloud environments or cloud-like settings (will not explain the latter term), you want to do away with the traditional Apache (or LightHTTPD, etc.) + PHP setup in favor of ...


-- a small,
-- portable
-- PHP-capable
-- web server.


The following figure will show you a standard usecase for such a setting.


You have 2 locations that need to talk to each other over HTTP. Since basically all cloud (and others as well) APIs today are HTTP -- or RESTful if the use a fancy word, this is quite a common case. The easiest way to do this is:

(1) To use wget (here is a link for Windows native version but I personally use Linux and cygwin versions) when you need to initiate a request to the other side, and
(2) To listen to requests from the other side using your mini web server.

Never mind the ports and all such details. What's important is the model used by the pair to communicate in both directions.


Now, specifically about PHP. This is a crucial element. I hear some people still use Java. I have nothing against these people but my personal opinion is that PHP is a much better .. flexibility and otherwise ... programming environment. I migrated to PHP 7-8 years ago and never doubted this decision.


Now, you might think that there is a whole bunch of mini web servers? Nope. Even Nope-i-er when it comes to Windows. I personally went through:

- TinyWeb Server -- it has a PHP version which simply does not work. It does run but you cannot get $_GET, $_POST and some other important stuff to work. Was very disappointed because this was the most promising version.
- XAMPP Portable. There is nothing portable or mini about this server as it is half-a-Gigabyte when decompressed. Could not get it to work either. First, Apache complained, then PHP did not run, etc. Had to quit on that one, too.
- Lighty2Go. Very promising name. Very disappointing results. Specifically no PHP support.


To cut a long story short, the solution was in plain sight since PHP 5.4.x was released. This version of PHP has a mini-server mode. Have been using it for a week now and have had zero problems. After all, it is about time PHP found out a way to serve its scripts without needing to go through Apache.

To run the server, you simply run:
php -S localhost:[YOUR PORT like 8001, etc.] -t /path/to/web/root


Some side notes on the convenience of this solution:
(1) I already have PHP everywhere. Windows native, Windows/Cygwin, Linux, virtual machines, added to XCP hosts, etc. Meaning that I get the server without any additional work.
(2) Easy to start and stop it. Temporary solution is exactly what we need in cloud applications. You never have anything permanent.
(3) PHP Server can now become a command line tool like wget. Again, simpler to understand and use. I enjoy having access to Cygwin environment while running the server.



Strongly recommended.