Django-like routing in PHP
tags: dev django php regexp route
05 Jul 2008 16:06
As I've recently work with Django, the way it does the URL-based routing seemed really cool for me. I missed that in PHP, so I decided to code something like this.
Here is a class that uses (extends) my Controller class that does the routing:
class Controller_Ajax_Auth extends Controller_Ajax { protected $routes = Array( ':^info$:' => 'info', ':^challenge$:' => 'challenge', ':^login$:' => 'login', ':^logout$:' => 'logout', ); protected function info($url) { $r = Array(); /* something */ $this->ajaxResponse($r); } protected function challenge($url) { /* $q = something */ $this->ajaxResponse($q); } protected function login($url) { /* set $auth to true if logged */ $this->ajaxResponse($auth); } protected function logout($url) { /* logout */ $this->ajaxResponse(null); } }
This mainly routes URLs info, challenge, login and logout to corresponding methods in the same object.
But you can route out of the object to other Controller subclass instance:
protected $routes = Array(
':^auth/(.*)$:' => 'Controller_Ajax_Auth',
);
This gets URL and passes what's after auth/ to the new object of class Controller_Ajax_Auth (see the code above). Generally the first ()s in the left side of each line define what's passed to the method/object on the right side.
The controller has abstract errorHandler and defaultAction methods that need to be overridden. The first is called when a exception is thrown in a performed action. The latter is called, when routing comes to some object and then no routing line matches.
Comments: 1
Mirror Server
tags: blog dev lighttpd mirror php wikidot
24 Jun 2008 12:55
Today I've (almost) managed to create a mirror server for wikidot.com service.
Features:
- CentOS distribution
- almost live Wikidot read only mirror
- database is replicated from the original service in real time to this server
- user uploaded files are replicated in real time to this server using FS mirror
- avatars are to be mirrored with rsync every now and then
- uses Portable IP address: 67.228.37.27
- lighttpd serves ALL content with FastCGI PHP
- database is read-only (as being replication slave)
- CVS configured to use SSH keys (no password asking)
- Wikidot PHP source mainly from the current production server
- Improvements (from CVS): uploaded files served like in OpenSource version
Problems:
- FS mirror is not 100% exact, it may not synchronize some (little fraction of) files every now and then, so we must rsync them additionally, to make sure nothing's lost
- if you were logged in to Wikidot before, it'll complain about not being able to write to ozone_session (because it's read only)
- Flickr Gallery not working and causing the whole page to display just nothing
- magic file recognition not working (it may be a problem in PHP configuration or an extension):
PHP Warning: finfo_open(): Failed to load magic database at '/usr/share/misc/magic'. in /var/www/www.wikidot.com/wikidot/php/utils/- on line 3
PHP Warning: finfo_file(): supplied argument is not a valid file_info resource in /var/www/www.wikidot.com/wikidot/php/utils/- on line 4
PHP Warning: finfo_close(): supplied argument is not a valid file_info resource in /var/www/www.wikidot.com/wikidot/php/utils/- on line 5
UPDATE: Flickr problem solution:
- yum install php-pear-HTTP-Request
- chgrp lighttpd /var/lib/php/session
Remember:
- when switching to mirror, we must restart memcached (or force to invalidate every item in it)
Comments: 2
PingBacks To Come To Wikidot
tags: back blog dev ping pingback wikidot work
06 Jun 2008 15:52
I'm currently working on PingBack implementation (both server and client) for current Wikidot software.
The documentation for PingBack is located here: http://hixie.ch/specs/pingback/pingback
The changes will be available on the wiki farm www.wikidot.com and will be incorporated in the open-sourced version www.wikidot.org
We've noticed there are many posts on Wordpress about Wikidot, bunch of them:
- http://docudork.wordpress.com/2008/02/10/wikidot-platform-released-as-open-source-under-affero-gplv3-license/
- http://joeos.wordpress.com/english-education/wikidot/
- http://compmatsci.wordpress.com/2007/12/29/wikidot-ing/
- http://jonnyengland.wordpress.com/2007/05/08/wikidot/
and we want to make a smart move to let people from both services (and many more) know what happens on the other.
PingBack is also known to work for many many other services than just WordPress.
Comments: 1
Ubuntu Server 7.10 Wikidot Clean Install
tags: blog dev machine server ubuntu virtual wikidot
12 Mar 2008 21:10
After creating-a-space-for-virtual-machines-host it's time to prepare a very first productional Wikidot installation on a virtual disk image.
The problems I've encountered:
1. Compiling the PCRE not gave me the expected results (using heap for recursion matches).
More to come…
