To be honest, I’m a bit fed up with Drupal lately. We’re stuck with an ever-growing fat Drupal6 site, and the monster doesn’t get easier to maintain. The question isn’t if we will upgrade, but to what we will upgrade. The logical upgrade to Drupal7 will be enormous because our website has over 150.000 lines of custom php-code (not mentioning css, js, themes). So moving to Drupal 7 or creating something entirely new based on a framework… I don’t dare to say how much difference in time it will make, but I do know that the new thing must be a giant step forward to what we have now.
Why moving from Drupal to a Framework?
As much as I love Drupal, the thing is… a lot of modules do kind of what I want, but they don’t do exactly what I want. Customizing a contributed module sometimes takes me as long as I would write it myself. Especially when there’s little info in the README-file or when there are hardly any comments in the code. To give you an exampe: it’s faster to lookup the url for the admin-page in the menu-hook, than to find it in the documentation or in the navigation.
Plus, what irritates me the most. When you have +75 modules, +100.000 nodes and +10 currently logged in users, the thing gets slow.. slooowww! Even with advanced caching tools such as Memcached, view-cache or Varnish, the thing still goes slow, even on a dedicated server. No wonder: every hook is checked for each and every request.
So I’m looking for something faster and more OO-like. I have a C#-background and the way classes are mimicked in php (including inheritance, namespaces) is simply terrible. I’d dare to say Drupal goodbye, as long as Drupal 8 isn’t released an is more decent.
My comparison of PHP Frameworks
Pfhew, long introduction, but here’s my research on PHP-Frameworks. Briefly, a framework provides a set of functions and classes to help developers write code faster and more structured. Most of them implement certain design patters, of which MVC is by far the most popular. The aim of MVC is to seperate the database-talking-code (Model) from application-specific code (Controller) from html (View). It also features a URL-mapping system to set “clean url”-rules and to separate the code-files from the actual urls (eg: /bootstrap.php shouldn’t be accessible through a browser).
Some devs use the bootstrap of a CMS as a framework-starter (like my RSS-boostrap), but it should actually be the other way around: a CMS should be build on a framework. Drupal8 will (maybe) rely on parts of Symfony2, but that won’t be out till 2014.
Continue reading “PHP Frameworks, which to choose in 2013? A comparison.”…
Like previous years DeWereldMorgen.be organizes an Ubuntu Install Party. Be present Sunday May 25th in De Vooruit. All details.
I upgraded my Ubuntu 10.04 to Linux Mint 14. After installing LAMP I got a Drupal WSOD on a previously well working site. As it turned out most errors came from deprecated php-functions and deprecated call by references to functions, introduced with the release of PHP 5.4.
At first I was a somewhat encouraged to solve those deprecated functions, but I gave up pretty soon. Drupal 6 isn’t designed for 5.4. Tweaking Drupal feels the same as upgrading to Drupal 7. Therefor, I keep it to PHP 5.3.
To downgrade 5.4 to 5.3 I recommend this script on the Ubuntu forums.
When installing the combo php5-fpm together with Nginx or Apache, you might run into this error:
[error] 4942#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: example.com, request: “GET /phpinfo.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “example.com:80”
This is actually not an nginx error but a php-error. Nginx tries to contact php5-fpm, but fails in doing so. This is because it’s probably not running, or because the configuration is wrong.
Check if it’s running
To troubleshoot this, test if fpm listens on 9000. You can do this with telnet.
sudo netstat -tlpn | grep :9000
Telnet should return “Connected to 127.0.0.1”
Netstat should return a line starting with “tcp” and ending with “LISTEN”
If it doesn’t return anything or if it returns an error, it’s because fpm is not listening on port 9000. To solve this:
sudo gedit /etc/php5/fpm/pool.d edit
edit the line that says “listen = ” to:
Then restart fpm:
sudo /etc/init.d/php5-fpm restart
You don’t even have to restart apache or nginx. It should work right away.
Instead of logging to the database, it could make more sense to log to the operating system.
- The OS has already a great way of maintaining logs, so there isn’t really any need to have a separated database logging.
- The options to maintain or report logs with the OS are much larger than the default Drupal database logging system.
- Database logging eats away performance from your server, certainly when Drupal writes tons of logfiles each day.
- Any shared hosted website can’t use this option, because they have no access to the OS’ logsystem.
- If your website is maintained by a so called “webmaster” or a “not so technically equipped person”, it may be easier to log to the database, because nontech persons would generally prefer to access the logs through the Drupal admin interface instead of using some dodgy Unix command. Of course, you could ask yourself if a nontech person is anything with the Drupal logs in the first place.
Continue reading “Write Drupal logs to rsyslog instead of to dblog”…
Our main RSS-feed at DeWereldMorgen.be is the most requested page next to our homepage.
It seems logic, think of how many rss-readers hourly check the feed. And, think of how many cpu and RAM that consumes, certainly with a fat system like Drupal.
An RSS-feed is easy to make in PHP. All you need is one custom query and a decent library like the Universal Feed Generator to generate the XML.
Create stripped version of Drupal setup
I used the minimal code that is needed to work in the Drupal framework. So I made a blank php-file in my www-root with this code:
This code has the security and functions of Drupal, but without the menu’s, theme’s, and a lot of module hooks. You don’t need a menu or a theme to create an RSS-feed, do you?
So I created my RSS-feed with just this in my php-file:
- the drupal_bootstrap function
- the Universal Feed Generator library included
- one query with db_query()
Let’s see performance wise. This is the report of a feed generated based on a user’s blog and articles. Memcache was not cleared before execution. Stats are generated with XHProf.
|Normal setup||My stripped setup|
|Number of function calls||115.200||18.400|
|Consumed RAM||126 MB||62 MB|
|Total execution time||1.169 MS||462 MS|
|Number of database queries||33||15|
|Query execution time||137 MS||80 MS|
Performance wise, my solution is twice as fast.
These stats are generated when caches were cleared.
|Normal setup||My stripped setup|
|Number of function calls||3,284,343||83,330|
|Consumed RAM||172 MB||76 MB|
|Total execution time||9,131 MS||1,000 MS|
|Number of database queries||926||131|
|Query execution time||769 MS||183 MS|
9x as fast. 7x less queries.
Of course, this is just for the first run, but still.
More soon. Please discuss this idea.
This concerns an error in Bamboo-Invoice. When I wanted to print a pdf, I got the following error in Apache:
[notice] child pid 16395 exit signal Segmentation fault (11)
(16395 could be any number)
The cause of any “Segmentation fault” is probably PHP related. It could be because of a bad php-code compilation, or because of PHP code-error that couldn’t be caught like it would normally.
The reason here was obviously a bug in Bamboo-invoice. You can define your own corporate logo in /img/logo/logo.jpg but since I don’t have a logo at the moment I removed the file (as written in the manual). This caused the error.
Putting the image back (or any other image) resolved the error.
- Published:October 4th, 2012
If you want to commit your changes into a new branch, you can use git-stash.
Git-stash cuts all the changes you made till the last commit and keeps them in “the stash”. Later you can paste those changes from “the stash” somewhere else.
For example: you work on bug A on the master branch. Suddenly your boss comes in and demands an immediate fix for bug B. The fix for bug A isn’t complete yet, but you don’t want to loose the work you’ve already done.
This is the way to go:
Assume you’re on the master branch with uncommitted changes for bug A.
- git stash => save all your changes in the stash. The master is now reverted to the last commit.
- git branch bugfixA => make a branch for bugfix A
- git checkout bugfixA => work on the bugfix A branch
- git stash pop => “paste” the changes from the stash. Your files look now just like before.
- git commit -a -m “debugging A” => commit the changes
- git checkout master => now you’re on a clean master branch. Now you can choose. Either you create a new branch for bugfix B or you continue working on the master-branch.
In case you’ve installed Varnish but not Pressflow (for Drupal 6), following scenario may happen:
- User A logs is, gets sessionid A
- User A changes something and loads a new page
- While loading the new page, a js or css-file is being downloaded from Varnish (example: /sites/default/files/js/js_79eb17289b3a88ec931b6f4bdb728282.js)
- The next file that is being downloaded is a jpg. This file doesn’t come from the Varnish cache and gives a new sessionid to the user (sessionid B)
- The requested page is being served correctly because it was requested with sessionid A. The user is unaware that he has a new sessionid because it happened during the loading of the page elements.
- The user clicks on another page and sends a new request with sessionid B.
- Drupal checks sessionid B and sees that it the session belongs to an anonymous user. Result: the user gets an “Access Denied” and is logged out.
Solution: install Pressflow. It will stop giving sessionids to the client.
(this post only applies if you have installed Varnish)
This one gave me headache: the Mollom module in Drupal 6 returned a 401: unauthorized. However: there was no firewall, no incorrect key, and I really got a response back from the server. Top of the bill: it worked on my dev-machine but not on the server.
Till I noticed the time of log reports didn’t match the real time. It was 17:15 while Drupal said 16:58. A time difference of almost 20 minutes. I set the time correct and ta-dah: Mollom works.