-->

Author Archive

NGinx: Custom error handling

by devarni on 18 May 2010, under Howto

I will give you a idea about the easy implementation of error page handling with Nginx.

1. Setting error handler

Error handler can be set with the error_page directive. More about this directive you can find here.

Do this in your server block but better use a generic file and include this in every virtual host server block. I use for this a file “vhost” with all such settings.

The handler or html files are placed in a separate folder outside the webs. You can use a folder inside your Nginx settings (I use here for example a “html” folder).

The location block is needed to pass the correct root and file to php fastcgi. In this example I use a file “fastcgi”  with this mostly used lines:

fastcgi_pass   unix:/tmp/fastcgi.socket;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include fastcgi_params;

Here the part in the server block (or in your generic vhost file for including):


# error handler, codes can also be combined
error_page 401 /error.php?c=401;
error_page 403 /error.php?c=403;
error_page 404 /error.php?c=404;
error_page 500 /error.php?c=500;
error_page 502 503 504 /error.php?c=50x;

# serve error.php from /etc/nginx/html folder
location /error.php {
   root /etc/nginx/html;
   include conf/fastcgi;
}

2. PHP file

The error.php file will be called with the URL encoded error-code, so its easy to grab this code in the PHP file from the superglobal $_GET array.

To map this error code to a message string, use a associative array and a function to return the string.

This is the part in the error.php file:


<?php

//mapping array for error code to message string
$_err = Array("401" => "Autorisierung erforderlich! - Authorization Required",
    "403" => "Zugriff ist nicht erlaubt! - Access forbidden",
    "404" => "Seite wurde nicht gefunden - Page not found",
    "500" => "Interner Serverfehler - Internal Server Error",
    "50x" => "Seite ist momentan nicht verfügbar. Bitte Anfrage später wiederholen.
-
The page is temporarily unavailable. Try again later."); // get the error string function errorString($error) { global $_err; foreach ($_err as $key => $val) { if ($key == $error) return $val; } return "Unknown Error"; } isset($_GET['c']) or die("Unknown Error"); $error = $_GET['c']; $str = errorString($error); ?> Error <?=$error?>: <?=$str?>

You can format the error page as you like. But remember: the web root url will be the actual virtual host! Easiest way: use inline CSS. If this is not your preferred way, place the css file in a virtual host (eg. your default virtual host)

Leave a Comment more...

Nginx: phpmyadmin configuration

by devarni on 13 May 2010, under Howto

This configuration is used to access phpmyadmin as a “subfolder” of the domain like:

http://mysite.com/phpmyadmin

The location will be append to the root! For a similar behaviour like the Apache configuration, you could use the “alias” directive

My phpmyadmin installation is under /usr/share/phpmyadmin, thats why I use /usr/share as the root.

server{
...
    location /phpmyadmin{
        root    /usr/share;
        index   index.php;
    }

    location ~ \.php$ {
        set $php_root   $document_root;
            if ($request_uri ~* /phpmyadmin) {
                set $php_root /usr/share;
           }

        fastcgi_pass   unix:/tmp/fastcgi.socket;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
}
Leave a Comment more...

Server Benchmark: Apache, Nginx, Cherokee, Lighttp

by devarni on 13 May 2010, under Networking

Quick Benchmark of Apache, Nginx, Cherokee, Lighttpd

A short benchmark of this 4 server with dynamic and static content.
All server provides the same functionality like URL rewriting, password protected folders/files etc. but all have their own way to do that ;)
For shared hosting where the user has no access to the server configuration, Apache with the .htaccess file support is a good choice.

I used the benchmark tool from Apache ab -n 50000 -c 20
php-cgi goes over a Unix socket

Dynamic Content (PHP)

Server Requests (sec) Transferrate (KB/s)
Apache 2.2.14 2125 11684
Nginx 0.7.65 1734
1861
9436 (php-cgi)
10115 (php-fpm)
Cherokee 1.0.0 2119
2103
11562 (php-cgi)
11454 (php-fpm)

Static content (14785 Bytes HTML file)

Server Requests (sec) Transferrate (KB/s)
Apache 2.2.14 6768 99593
Lighttpd 2.4.26 15782 213866
Cherokee 1.0.0 7602 111285
Nginx 0.7.65 10912 159828

More “real live” test with PHP and eAccelerator enabled

Cherokee/NGinx/Lighttp are using the same php-fpm socket

Server Requests/s Ø
Apache 2.2.14 2713|2744|2766 2741
Nginx 0.7.65 2416|2433|2418 2422
Cherokee 1.0.0 2702|2638|2694 2678
Lighttp 1.4.26 2492|2363|2540 2465

Results

There is a small difference between fast-cgi and php-fpm (alternative implementation of fast-cgi).
You should prefer php-fpm (will be included in PHP 5.4 or you must build it manually from source).

Apache and Cherokee are both excellent for dynamic content.

For static content Lighttp is the fastest server.

There is not _the_ best server but a good combination: Lighttpd or Nginx as a proxy for serving static content, Apache or Cherokee for the dynamic content. Or a another proxy server like Varnish for static content and caching and Apache/Cherokee for serving dynamic content

For a PHP site with only 1 server running: Apache.

For a smaller memory footprint and if .htaccess is not needed: Cherokee (also the only server with a very good graphical admin interface)

Leave a Comment more...

Benchmark: VirtualBox vs VMware

by devarni on 10 March 2009, under Benchmark

Benchmark VirtualBox 2.1.4 vs VMware Workstation 6.5.1

Host: Ubuntu64, 4GB RAM, Core2Duo E6600, Samsung HD502IJ
Guest: Windows XP Home, 1GB RAM, 8GB virtual disk
Benchmark Software: SiSoft Sandra Light, HD Tune

Short benchmark of this both VM

VirtualBox VMware Workstation
HDTune
Min (MB/s) 26 5,7
Max (MB/s) 250 803
Average (MB/s) 177 392
Access time (ms) 0,4 0,2
Burst rate (MB/s) 129 488
CPU Usage 56% 17%

Sisoft Sandra
Dhrystone ALU (GIPS) 22,70 7,35 (*7,34)
Whetstone iSSE3 (GFlops) 18,64 6,26 (*5,92)
Multimedia: Integer (MPixel/s) 77,21 15,76 (*16,90)
Multimedia: Floating Point (MPixel/s) 45,77 10,04 (*10,19)
Multimedia: Double (MPixel/s) 23,96 5,14 (*4,28)
Physical Drives (MB/s) 109 357
Combined Performance Index 671 802

*) Dual CPU Mode

Resumee

VirtualBox shows better computing performance, which benefits for desktop applications and multmedia based operations. Interesting: the dual CPU mode in Vwmare has no advantage over the single CPU mode.
Certainly we can say: Virtualbox for desktop applications, Vmware for server but for the combined performance VMware ist the winner.

Leave a Comment :, , , more...

Flash symbols with Actionscript3 in Flex

by devarni on 23 February 2009, under Programming

The difference

Don’t forget: Flash != Flex. Flex uses elements from Flash but is built on own classes. If Flash and Flex should play together we need a interface.
MovieClip is a display object in Flash and UIComponent is a display object in Flex. But we can wrap a MovieClip into a UIComponent, so the Flex UIComponent becomes a container for our Flash MovieClip.
Here both files, at first the MXML file:





And the Actionscript file with the class:


package {
	import mx.core.Application;
	import mx.core.UIComponent;
	import flash.display.MovieClip;

	/*****************************************************************
	 * File: FlexApp.as
	 *****************************************************************/

	public class FlexApp {
		private var _app:Application;

		public function FlexApp(app:Application) {
			_app=app;

			var btn:MovieClip=new BtnStop();
			var flexui:UIComponent=new UIComponent;
			flexui.addChild(btn);
			app.addChild(flexui);
		}

		static public function initApp():FlexApp {
			return new FlexApp(Application(Application.application));
		}

		public function get app():Application {
			return _app;
		}
	}
}

How it works

applicationComplete in the MXML file is the eventhandler called from the application. Here we provide our handler, which must be a static member function of a class so it can be called later.
initApp() creates our class and passes a application object to the constructor.
Inside the constructor we create the MovieClip from the imported Flash symbol “BtnStop” (this symbol comes from a swc lib, created with Flash). Then we create a Flex UIComponent container and add our MovieClip as a child. The UIComponent can now be added as child of the Flex application.

Leave a Comment :, more...

The Tools…

by devarni on 22 February 2009, under IDEs & Development Tools

Overview of development tools for Flash/Flex

Tool Price Link
FlashDevelop 3 rc1
Flex, Actionscript IDE (Windows) free http://flashdevelop.org

Adobe® Flex SDK3
Flex Software Development Kit (Compiler, Framework…) free Flex download

Adobe® Flash® CS4
Design and programming of Flash animations $699/831€ 30-day trial

Adobe® FlexBuilder3® Professional
Flex programming and visual design of MXML, based on Eclipse Standard: $249/213€
Professional: $699/593€
30-day trial

Ensemble Tofino
Flex plugin for Microsoft Visual Studio® free http://www.ensemble.com
Leave a Comment :, more...

FlexBuilder3 with Aptana/Eclipse 3.4.1 “Ganymede”

by devarni on 22 February 2009, under IDEs & Development Tools

FlexBuilder3 is based on Eclipse 3.3.1 and doesn’t work unfortunately with Eclipse 3.4.1 “Ganymede”.
But Eclipse “Ganymede” has a feature for easy integration of plugins called “dropins”, therefore under Eclipse 3.4.1 exist a “dropin” folder…

Close Eclipse and copy the complete Flexbuilder folder (standalone or plugin) inside this “dropin” folder. Restart Eclipse and now you should have the complete Flexbuilder envoirenment available!
Flexbuilder can be found with the default installation path at C :\Program Files\Adobe.

3 Comments :, , , more...

FlexBuilder vs FlashDevelop

by devarni on 22 February 2009, under IDEs & Development Tools

A short comparison of Flexbuilder3 with FlashDevelop 3

FlexBuilder 3


Pro

  • Easy debugging and profiling
  • Automatic adding of imports and organizing of imports
  • Visual designer for MXML
  • Because of Eclipse: support for other languages (eg. with Aptana, PDT…) and extendible with Eclipse plugins. So features like “Code Snippets” (CFEclipse), automatic code generation for Getter/Setter (Monkey Script) are usable
  • Class Wizard
  • Support for ASDoc comments
  • Support for virtual folders/files (links to external files/folders handled intern by Eclipse, so also working on Windows)
  • Refactoring (renaming of classes, functions, properties with automatic adaptation of dependencies)

Con

  • Commercial license
  • Plugin doesn’t work with all versions of Eclipse (eg. is not working with Eclipse Ganymede 3.4.1 or 64bit versions)
  • Searching, adding and configuring the missing features with Eclipse plug-ins is often complex
  • Code assist average and sometimes buggy eg. if correct imports are missing (“java.lang.NullPointerException”)
  • No Code Formatter or automatic generation of getter/setter (only with Eclipse plugins like Monkey Scripts, CFeclipse, Flexformatter “FlexPrettyPrintCommand”...)
  • No package explorer for SWC files

FlashDevelop

Pros

  • Free and OpenSource (developed with C#)
  • Lightweight
  • Best available Code Assist for Actionscript
  • Contextual code generation (getter/setter, variables, event handlers)
  • Code Snippets
  • Automatic adding of imports
  • Extendible with plug-ins
  • Support for ASDoc comments
  • Package explorer (shows classes and symbols from SWC files)

Cons

  • Only for Windows
  • Plugins often not working in newer versions and many plug-ins are only rarely updated
  • Debugging only with a plugin and more at an early stage
  • No visual designer for MXML
  • No class wizard
  • No code formatter
  • No support of virtual folders/files (“links”) insides the project
  • No refactoring


My recommendation:

For debugging, visual design of MXML: FlexBuilder
For mostly coding of Actionscript under Windows: FlashDevelop.

Leave a Comment :, more...

Looking for something?

Use the form below to search the site:

Archives

All entries, chronologically...

© 2009 by Frank Arnold | About