Amazing things to do with PHP and cURL

Posted on Feb 06, 2012

cURL, and its PHP extension libcURL, are very useful tools for tasks like simulating a web browser, submit forms or login to a web service. In this article, I’m going to show you some amazing things that you can do using PHP and cURL.

Check if a specific website is available

Want to know if a specific website is available? cURL is here to help. This script can be used with a cron job to monitor your websites.

Don’t forget to update the script with the url you want to check on line 3. Once done, just paste it somewhere and it will let you know about the site availability.

cURL replacement for file_get_contents()

The file_get_contents() function is very useful but it is unfortunely deactivated by default on some webhosts. Using cURL, we can write a replacement function that works exactly like file_get_contents().

Twitter: test friendship between two users

If you want to know if a specific user is following you (or someone else) you have to use the Twitter API. This snippet will echo true if the two users specified on lines 18 and 19 are friends. It will return false otherwise.

Convert currencies using cURl and Google

Converting currencies isn’t very hard to do, but as the currencies fluctuates all the time, we definitely need to use a service like Google to get the most recent values. The currency() function take 3 parameters: from, to, and sum.