Browsing articles in "Tips"
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 »

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.