Jun 10, 2011
Usu

Wanna play Les Paul Google Doodle forever and ever?

Thanks to gensanblog.com who ripped it and made it available for everyone, I mirrored it here for neverending fun.

Google ♥

May 18, 2011
Usu

Simulate real users load on a webserver using Siege and Sproxy

We all know ApacheBench which is a really great tool for “brute-force” benchmarking, but what if we need to simulate n real users browsing a website in a plausible way?

Well, Siege and Sproxy serve this exact purpose!
Sproxy is a proxy that we can use to collect a list of urls to feed Siege with, let’s see how.

First, we obviously need to install all the software we will need.

Continue reading »

Jan 5, 2011
Usu

Accessing Miso API: a sample PHP application

Miso recently introduced the ability to access their data through API which is really great, I’m already using it in production on Italiansubs.net.

The documentation (that you should definitely read) is well written and  easy to follow if you have any experience in working with json API and OAuth, but if you haven’t, and you don’t know Ruby (the programming language used for their sample application) it’s possible to find it tricky.

So, here’s the sample PHP application:
Continue reading »

Oct 11, 2010
Usu

How to upgrade to Ubuntu Server 10.10 (Maverick Meerkat)

The new release of Ubuntu is out! Anyway, if you’re running Ubuntu Server on a production system, I would recommend you to stick with the LTS version (10.04 Lucid Lynx).

Here’s how to perform the upgrade in 3 simple steps:

First, make sure you have the update-manager-core package installed:

sudo apt-get install update-manager-core

Now we use nano to edit /etc/update-manager/release-upgrades and set Prompt=normal

nano /etc/update-manager/release-upgrades

Last step, launch the upgrade tool and follow the instructions:

sudo do-release-upgrade -d
Aug 11, 2010
Usu

How to run a cron job every X seconds

There’s a really simple way for doing this directly in crontab: putting the process to sleep.

Let’s see how: imagine you need to run a PHP script every 10 seconds to check whether a webiste is responding, here’s what you would need to put in crontab:

* * * * * /usr/local/bin/php /var/www/uptime.php
* * * * * sleep 10; /usr/local/bin/php /var/www/uptime.php
* * * * * sleep 20; /usr/local/bin/php /var/www/uptime.php
* * * * * sleep 30; /usr/local/bin/php /var/www/uptime.php
* * * * * sleep 40; /usr/local/bin/php /var/www/uptime.php
* * * * * sleep 50; /usr/local/bin/php /var/www/uptime.php

What we’re doing here, is starting 6 processes altogether every minute with progressive sleep times and that results in running the PHP script every 10 seconds. As simple as that.

Aug 4, 2010
Usu

How to automatically update your FeedBurner RSS using cURL

FeedBurner is a pretty cool service that provides insights and many other useful information about the RSS Feed of a website, though if you need your users to be notified immediately after a new item is posted on the website you’ll find that there is a nasty limitation in place: the feed is only updated every 30 minutes.

Fortunately FeedBurner also provides a ping service that let you manually update your RSS Feed; but visiting a website every time you need to update your feed isn’t very practical, instead we can use cURL to do this automatically every time we publish a new article or something.

Here’s the PHP code (you need to make sure that your hosting has cURL enabled):

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, 'http://feedburner.google.com/fb/a/pingSubmit');
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, 'bloglink=http://www.example.com');
$result = curl_exec($ch2);
curl_close($ch2);

You need to place this right after the code that publishes a new item on your website, so that the RSS Feed is immediately updated with the new articles (or whatever you are publishing).

Another way to do this is by putting the code in a cronjob and run it every X minutes, but use this only if you can’t get  the other method working, it’s way better.

Here’s the code to use cURL directly from the command line (use this if you are planning to go with the cronjob method):

curl -d 'bloglink=http://www.example.com' http://feedburner.google.com/fb/a/pingSubmit

Also you don’t need to provide the full RSS Feed URL, the website base URL will do just fine.

Aug 2, 2010
Usu

Benchmark: libmysql vs mysqlnd

A few days ago I found out about the existence of the MySQL Native Driver (mysqlnd) that has been introduced in php 5.3, it is a replacement for libmysqlclient and it is licensed under the PHP license, therefore avoiding the need of the FOSS License Exception.

The purpose of this article isn’t explaining what mysqlnd is and what it does, for that you can start by reading the official documentation and this nice blog post.

I did these benchmarks mostly because I couldn’t find any proper comparison between the two drivers and I wanted to know which driver I should be using on all the servers I manage (performance-wise), I then figured that making this public could be useful to someone else, so here it is.

Continue reading »

Aug 2, 2010
Usu

ApacheBench Script

Quoting from Apache Benchmark official website:

ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs.

In order to make sure that a benchmark involving the use of ApacheBench is run without any distortion due to, for example, wait times that could lead to cache expiration I needed a very simple bash script, so here it is:

#!/bin/bash
NUM=1250
CONC=3
SLEEP=15
FILENAME=Benchmark
URL=http://www.example.com/
echo "a started"
ab -n $NUM -c $CONC $URL > $FILENAME-$CONC-$NUM-a.txt
echo "a completed"
sleep $SLEEP
echo "b started"
ab -n $NUM -c $CONC $URL > $FILENAME-$CONC-$NUM-b.txt
echo "b completed"
sleep $SLEEP
echo "c started"
ab -n $NUM -c $CONC $URL > $FILENAME-$CONC-$NUM-c.txt
echo "c completed"
sleep $SLEEP
echo "d started"
ab -n $NUM -c $CONC $URL > $FILENAME-$CONC-$NUM-d.txt
echo "d completed"
sleep $SLEEP
echo "e started"
ab -n $NUM -c $CONC $URL > $FILENAME-$CONC-$NUM-e.txt
echo "e completed"
exit 0
Jul 29, 2010
Usu

Di nuovo online!

Era un po’ di tempo che avevo intenzione di rimettere su il blog personale, tuttavia volevo evitare di farlo utilizzando WordPress visto che è scritto senza rispettare le più basilari regole per una programmazione corretta quantomeno sensata.

Cosa scegliere quindi? Sembra facile, ma non sono poi molti i CMS PHP creati specificamente per l’amministrazione di un blog. In attesa che Antonio sviluppi la piattarforma di blogging ideale mi sono messo alla ricerca di qualcosa che facesse al mio caso e, dopo essermi imbattuto in cessi intervallati da CMS aggiornati al 2005, pensavo di averlo trovato: Serendipity.

Beh inutile dire che è stato un gigantesco FAIL: dopo averci perso una giornata a preparare il tutto, installare i plugin necessari (ne servono un po’ dato che le funzioni “out of the box” sono davvero basilari), modificare un po’ il tema, ed altre cosucce; vado finalmente a spostare i files nella root del sito per mettere online il tutto (avevo installato il CMS in una sottocartella per i test), modifico di conseguenza la configurazione e… puff! Non l’avessi mai fatto!

Ecco il simpatico errore apparso:

serendipity error: could not include /path/serendipity_config_local.inc.php - exiting.
Please create the file yourself or check permissions

Inutile dire che il file c’era, aveva i permessi giusti, ecc. Dopo altro tempo perso tra infinite prove e googlate inutili (sembra che questo problema, una volta presentatosi, nessuno sia mai riuscito a risolverlo) ho optato per un bel “rm -r serendipity/” e ho, a malincuore, (re)installato WordPress.

Ecco, avevo bisogno di un primo post per mettere quantomeno online il tutto, pur essendo io il re dell’incostanza e il peggior nemico della grafica cercherò di lavorare al blog per renderlo decente e addirittura(!) pubblicare qualche contenuto interessante.