Below you will find pages that utilize the taxonomy term “PHP”
Drupal 6 released

Drupal the open source content management system has a new fresh release Drupal 6.
Update: It seems CCK and VIEWS aren’t compatible with Drupal 6 yet, does anyone use Drupal without CCK and VIEW?
CodeIgniter setup tips
- Fix mod_rewrite to have clean URLs, and get rid of “index.php” part.
- Edit “config/config.php” and change the following:
// Setup your base URL
$config['base_url']="http://rayed.com/ci/";
// No need for index.php
$config['index_page'] = "";
// Remove AUTO and Put PATH_INFO
// this will allows you to pass variables as URL
// segments or Query string "?id=1"
$config['uri_protocol'] = "PATH_INFO";
- Setup your database configuration “config/database.php”
- Auto connect to database, edit “config/autoload.php”:
$autoload['libraries'] = array('database');
- Edit “config/routes.php” to change default controller:
$route['default_controller'] = "users";
CodeIgniter yet another PHP framework

For the last year I spent a lot of my PHP time playing with CakePHP I like it at first, but when I tried to build large applications with it I noticed it have major issues with performance, plus I really had difficult time dealing with it is strict naming convention and it object-relational-mapping (ORM).
Few days ago I read about CodeIgniter framework and its similarities to CakePHP and its amazing performance, so I went and visited their website again, I heard about CodeIgniter before from Abdullah Aldosari (I miss our technical discussions) but when I visited the website I wasn’t really impressed, but the new website looks much better, so judging by the look improvement alone I decided to give it a try 🙂
Learning Drupal

Every Eid vacation I end up with an extra free time, I usually use it to learn new stuff, the latest vacation I decided to learn Drupal. Drupal is a Content management system (CMS), it is basically a software to help you manage your content.
Drupal is a modular and customizable CMS, you can use it to build different types of web sites, a Blog, company or organization web site, community website, you name it.
alriyadh.com new search engine

After serving Alriyadh.com the past 3 years, I am replacing Swish-e with Solr search server, Solr is a search server based on Lucene text search engine.

Solr has many advance features I didn’t utilize most of them yet, but hopefully you will see them soon. I will write a post about Solr and how it works and its integrate with PHP soon.
For now please have a look at it and tell me what you think.
Moved to a new server
rayed.com to new server with upgraded softwares:
FreeBSD 6.2
Apache 2
PHP 5
MySQL 5
Muntaqa the best of Arabic email groups
Today me and Abdullah launched Muntaqa.
Muntaqa is a website that collect large number of email groups, e.g. AbuNawaf, and displays them in a single page, people can vote, bookmark, and comment on all emails.
In the front page you will get the most popular emails, so you want miss any interesting emails in the Arabic web sphere 🙂
Muntaqa works like Digg, but instead of submitting websites, we automatically submit emails from email groups. A big population of computer users in Arab world (at least in Saudi Arabia) still consider the emails as the only form of publishing in the Internet.
Supporting right to left writing (for Arabic) in WordPress
UPDATE: I found an easier way to do the same thing Check it out
In my blog I write in both languages English and Arabic, but I have to switch text direction from the template default English direction “Left to Right” to Arabic “Right to Left”.
One way do to it is to add HTML tags in each Arabic entry.
Another way to do it is to utilize WordPress “Custom Fields” feature, WordPress allows you to add custom fields to any entry, so I add a new custom field to my Arabic entries, the key will be “wp_direction” and the value will be “rtl”.
lighttpd enters the Top 5
Lighttpd web server is becoming major player in the web server space, according to Netcraft Lighttpd is the 4th most popular web server on the net, and it is moving fast!
CakePHP under Lighttpd
After moving alriyadh.com to Lighttpd I had some problem making a CakePHP application I wrote to work properly.
I searched the net for a solution and I found this post, but unfortunately the solution they proposed didn’t work, I spent several hours trying to make it work until I gave up, I decide to do it from scratch and luckily it worked.
The mod_rewrite rules I used in lighttpd.conf file:
url.rewrite-once = (
"^/cake/(css|files|img|js|stats)/(.*)$" => "/cake/app/webroot/$1/$2",
"^/cake/(.*)$" => "/cake/app/webroot/index.php?url=$1"
)
Where cake is you cakePHP application.
Improving thumbnails quality
Inpired by Flickr’s Dirty Little Secret post, about how Flickr thumbnails make the photo prettier than the original photo.
The article suggest that Flick sharpen the image before it resize it.
So I did my own test, this the result and you are the judge:
Image 1, normal resize.
Image 2, sharpen before resize.


Sharpened and saturated +100:

All I need to know is how to do it from inside PHP.
alriyadh.com moved to lighttpd
Alriyadh.com website is now served by Lighttpd (aka Lighty).
I moved all static content from Apache to Lighty, Lighty “select” based design makes it ideal for I/O bound operation, i.e. disk and network operations. For this reason Lighty move all CPU bound operations to external process and communicate with them using FastCGI protocol.
This is what delayed my migration to Lighty, because I used to compile PHP with mod_php only and with FastCGI support, so I have to recompile PHP to enable it. Of course I spent few days testing, and I am still having some areas not covered completely.
Alriyadh.com previous polls
Recently I have improved alriyadh.com voting system, many of them are in administration area, some of these changes will be visible in the near future.
One of the new additions is the previous votes page:
http://www.alriyadh.com/php/vote/
Check it out, and keep in mind the design is still under work.
Memo to self: replace the word “vote” with “poll”
UPDATE: If you see weird colors in IE (7?) it is fixed now.
XCache new PHP optimizer
XCache is relatively new PHP code optimizer, written by “Jan Kneschke” the same guy who wrote Lighttpd web server.
After migrating Alriyadh.com to the new dual CPU servers, I had problems with APC PHP optimizer and locking, so I disabled the optimizer altogether, after all the CPU was very fast and it handled the load without any problems.
But lately with my increasing interest on Lighttpd I noticed XCache, I never heard of it before but after reading the web site, and the problem APC have with multi processors I decided to give XCache a try, and the best of all it was ready in FreeBSD ports, so I installed it and so far it doing a good job.
Java Package for FreeBSD
Installing Java on FreeBSD (my favourite operating system) wasn’t an easy task, you have to download Java files from Sun web site put them in a special directory then start a lengthy build process that never successed.
Fortunately FreeBSD Foundation has binary package for Java, all you need is to Download and install using:
# pkg_add diablo-jdk-freebsd5.i386.1.5.0.07.01.tbz
and you are done.
With Java on FreeBSD may be I will start playing with Lucene instead of Swish-e as Alriyadh search engine.
Things I want to write about but don’t have time
These days I really don’t have time on the Internet, but I really want to talk about some of these issue in more depth later.
- My phone line (including DSL service) is out of service for more than month, and until now no hope 🙁
- IGW the new ISU: STC is now handling Internet gateway operation, the service is still has some issues, and we are still understaffed.
- Dev4Islam: Project to devlope open source Islamic and Arabic software and services. We aim to collect data and make it available for other so they can build better software.
- Java + Delphi = C# Anders Hejlsber the creator of Delphi, create a great language for Microsoft.
- Lucene is a full text search library, exteremly fast, and the API is awsome. I tested it Lucene .Net port it is really super fast.
- Swish-e same as lucene, this what I use for Alriadh.com, still very good.
- Alriyadh.com new feature: user login for better experince, no need to rewrite your name and email when you want to submit a comment or send article to a friend, and you can bookmark your favourite articles, any thing else we should add.
Implementing Pingback in alriyadh.com
Pingback is a method for Web authors to request notification when somebody links to one of their documents. This enables authors to keep track of who is linking to, or referring to their articles.
Implementing Pingback feature is very easy, you need to add the following code to your template:
<link rel="pingback" href="http://www.alriyadh.com/php/xmlrpc/" />
This code will make other blogging software notify your software that it is linking to it, It do this by sending “pingback.ping” XML-RPC request to the given URL, when you get the notification you can add it to the database, email it, or do what ever you want with it.
lighttpd the new webserver in town
For the past 9 years I used Apache Web Server exclusively, Apache is very stable and feature rich web server. The only downsize is consuming a lot of computer resources, Apache is a multi-processes server which mean you will find many Apache process running in your system and if we say that each process cosume 2MB of RAM and you have 5 Apache processes running this mean it needs 10MB of RAM.
Python 2.5 Beta, and new Python website
Python, my favorite computer language (althought I don’t use it that often) released 2.5 beta version.
What amazed me that their website is now changed with new look, and Python has a new logo too.
Optimizing MySQL
The last 3 days we were facing many problems with Alriyadh.com web server, the server suddenly get very slow, and all requests times out. It took me very long time to identify the problem, I tried many things and every time I think it will solve the problem completely, but after few hours the problem appear again and he server start to crawl.
Until this moment I am not 100% sure the problem is solved, but during the process I learned many things, so I’ll share it with you and hopefully everything will go smoothly, if it doesn’t I have to learn new thing to figure out the problem.
JEdit the ultimate editor!
A year ago Waleed Alzuhair asked me about the reason I am still using Windows-1256 Arabic character set, intead of the new standard Unicode. My reason was the lack of good editor that support Arabic and Unicode, my favourite eidtor HTML-Kit doesn’t have any support for Unicode.
But lately while looking for an editor for Mac OS I found JEdit, it is a Java based editor which means it will work with any OS, it supports many charachter sets including Unicode UTF-8, another intersting feature is its support (through a plugin) of remote editing using both FTP, and SFTP (HTML-Kit doesn’t support SFTP).
SAUDI NET needs fresh graduates
SAUDI NET is hiring and we are looking for fresh graduates in CS/IS, we have very large expansions that will give you many great chances to work with different technologies.
SAUDI NET is part of Saudi Telecom Company (STC) so you will get all the STC employees benefits.
If you are intersted send me your resume at (rayed at saudi.net.sa)
FireFTP: FTP client inside Firefox
I always have trouble finding and recommending FTP clients to friends, I used to use WS_FTP but it isn’t free, same thing for Cute FTP.
Lately I didn’t use FTP client any more, because I start using HTMLKit it isn’t an FTP client per se, it is an editor with the ability to open remote files using FTP, so I do most of my file editing using it.
HTMLKit is great but it doesn’t support moving files or directories, or transfaering a complete directory. In these cases I usually log to the machine using SSH and do the need operations using the command line, but this not an option for most people.
Finally I upgraded WordPress
Today I had to finish writing some code for Alriyadh Worldcup web site, and I was expecting it to take at least 5 to 6 hours, and it had to be finished today, so I planned all my evening for that coding session
Fortunately I finished the job in 2 hours, and I had some extra time in my hand, so I decided to do something I planned to do for very long time, upgrade WordPress, so I sat down and upgrade it from version 1.5 to the latest version, alhamdu lelah the upgrade process was very smoth, althogh some features didn’t work, mainy the rich text editing feature.
Alriyadh.com wins ICT Excellence Awards
Yesterday, Alriyadh.com awarded the Middle East ICT Excellence Award in the “Print and Electronic Media of the Year (Print)” category from the Middle East Excellence Awards Institute.
Alriyadh Newspaper covered the story, and we received a great response from many people, thanks everyone:
- «الرياض»تحصل على جائزةالشرق الأوسط في تقنية المعلومات والاتصالات لأفضل موقع الكتروني
- «الرياض» تحصل على جائزة أفضل موقع إلكتروني في الشرق الأوسط
- موقع «الرياض» الإلكتروني.. عمل دؤوب وتطوير دائم(screen shots for alriyadh.com since opening)
- السحيباني: انتظروا المزيد من التطوير في موقع «الرياض» الإلكتروني
- شباب سعودي يتوج «الرياض» الإلكتروني باللقب
- تقنيون سعوديون: فخورون بفوز «الرياض» .. والجائزة ذهبت لمن يستحقها
- قراء «الرياض» يتفاعلون مع الفوز
Special thanks to Ahmad Alsuwailm for the great coverage.
CakePHP 1.0 released!
CakePHP version 1.0 is released, CakePHP in thier word is:
Cake is a rapid development framework for PHP which uses commonly known design patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility.
I have tried it few times and it is really intersting peace of software, many say CakePHP is Ruby on Rails clone.
Alriyadh.com new 404 page
Check it out:
404 Page
and give me you feedback, what to you think it should contain.
PHP output compression
PHP 4.0.5 and above added new feature to compress your PHP pages on the fly, all you need is the zlib extension, this how I configured it.
# vi /usr/local/etc/php.ini
:
zlib.output_compression = On
:
# apachectl graceful
Alriyadh.com front page size dropped from 20.5 K to 5.6 K, according to my tests almost 50% of browser don’t support compression, IE for instance turn off gzip compression support if you have bad firewalls (Zone Alarm), and even some IE extensions (specially ad wares) turn off the compression.
Caching: memcached vs MySQL
Several month ago I researched caching methods to use with Alriyadh.com, it was essential because we used old and slow hardware.
The result of my test showed that MySQL based caching was superior to memcached caching.
I did a new benchmark comparing MySQL, PHP memcache extension, and PHP memcache class.
The text is done by fetching the result of a complex query 1000 times, and calculated the time it took using my bechmark library (link dead!), times in seconds:
alriyadh.com news in your website, cut and paste
I developed a new Javascript based feed for alriyadh.com that can be included easily in any website, all you need is cut-n-paste some HTML code (mostly Javascript) into your web page and you will get all the news you need.
The script is customizable you can select the following:
- What section you want to view.
- How many links in each section.
- How do you want to view the links.
Give it a try and tell me what do you think, remember it is still under development, so please don’t complain about the design 🙂
http://www.alriyadh.com/static/feedjs/
alriyadh.com one man show!
Everyday at 11pm, alriyadh.com team start working on the next day issue, the job involve copying all contents from the printed version to the alriyadh.com content management system, the process involve 2 to 3 team members, and takes about 4-5 hours to complete.
But last Thursday was a special case, due to a planned vacation for one team member, and family issues for another member, Faisal Alenzi was the only guy working that night and he carried the whole show and published the whole issue on time by him self.
PostgreSQL and PHP (on Windows)
After installing PostgreSQL (15 minutes job), and playing with pgAdminIII, I decided to try it with PHP.
PHP & regular experssion named groups
This is a nice regular expression feature, sometime when you have complex regular expression, you could forget what each refer to:
$str = '2005-08-01';
preg_match('/(\d{4})-(\d{1,2})-(\d{1,2})/', $str, $m);
Now you don’t know which group is which part in the regular experssion.
Instead you can name all groups by using the format (?P<name>pattern) instead of just (pattern), then you can access this group by name you assigned it, so the previous regular experssion could be written like:
preg_match('/(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})/', $str, $m);
Tip on installing graphic support for PHP in FreeBSD
GD is a graphic library that enable PHP to manipulate images, to install it from FreeBSD port us:
# cd /usr/ports/graphics/php4-gd # make -DWITHOUT_X11 install
The tip is to use WITHOUT_X11 option this will save you from compiling X Windows which is needed for some of GD supported formats.
Caching method compared
I tested different types of caching, here is my times:
Method | Hit Time | Improvments over Miss |
---|---|---|
File | 0.00029 | 19337.93% |
MySQL | 0.00064 | 8762.50% |
memcached | 0.00103 | 5444.66% |
Altought File caching is much faster that the other two methods, it can suffer from file locking problems, and can’t be shared between more than one server.
memcached client used is written in PHP which will slow it down a little bit.
So MySQL seems the ideal choice 😉
New plans for alriyadh.com
When I started building alriyadh.com website I decided to generate all pages as static HTML files, I relied heavily on Server Side Includes (SSI) to build complex pages.
The main reason for this decision was the fact that the server was very slow on processing PHP files, espcially with a site with high load.
Generating static HTML files has its advantages but it also had many problems:
- Regenerate everytime you want to test a change
- Changing the design will cause regenrating the whole website, which could take forever.
- Generating complex pages is very hard, I had to rely on SSI.
- What to do with pages that change frequently, e.g. pages with comments.
- When importing old data, you need to generate them as well.
- Static HTML files performance advantage for frequently used data, like todays issue, but for old issues it just take a lot of disk space.
Soon I’ll start testing dynamicly generated of pages with these points in mind:
Ruby on Rails
Ruby on Rails is a web development framework written in Ruby computer language.
It is based on the Model-View-Controller (MVC) architecture.
Smarty does a good job in the areas of View-Controller in PHP language, but I always had a feeling that the model part can be improved, but no idea how. I raed a little about Object-Relational mapping but it seems very complicated and very restircting.
Ruby on Rails on the other hand does a good job in the these 3 areas, specially the Model part, they have something called ActiveRecord which maps database tables.
There are also PHP clone for Ruby on Rails, Cake PHP, it is still in its early phases, but could give a feeling of what Ruby on Rails can offer.
Interanet searching with Swish-e
Swish-e (Simple Web Indexing System for Humans – Enhanced) is really nice small program that index almost anything, I am playing with it at the moment and I am thinking of dumping my own search engine and replace it with Swish-e.
Swish has many features but the one feature that stroke me is the speed:
66,548 files indexed. 164,076,410 total bytes. 26,496,024 total words.
Elapsed time: 00:02:44 CPU time: 00:02:31
Indexing done!