Monday, June 29, 2009

Five ways to be a better PHP programmer

Here is a list of five things you should do (or not do) when you are starting out with PHP.

Don’t use XAMPP or PHP Triad

This is one of the most common and absolutely the worst mistake PHP beginners can make. Go to any PHP forum and you will see scores of threads on people looking for help on how to change their PHP settings.

If you want to earn a living through PHP coding, you should at least know how to install Apache and PHP. You don’t need go too deep into Apache configurations. Just enough to get the Apache-PHP combo up and running so that you are familiar with the php.ini file.

This knowledge will be immensely helpful when you start deploying web applications on production servers.

Set error reporting level to maximum

Configure your development environment to display all PHP warnings, notices and errors. This will help you code better and also help in catching potential bugs early in development phase.

You can change the error reporting level at runtime by adding the following code at the top of your PHP script:


// Report all PHP errors.
error_reporting(E_ALL);
?>

You can also control whether you want to display errors in the browser itself or whether you want to log the errors. Note: Displaying errors is not recommended for production servers.

Always check the manual first

Stuck on PHP coding problem? No sweat. Just checkout the PHP’s online manual, especially the User Contributed Notes. Chances are somebody has already faced your problem and has also figured out the solution. User contributed notes are full of useful hints and tips.

PHP is perhaps the only language whose manual is much more comprehensive than most of the books available in stores.

Analyze code of open source applications

Download some popular open source PHP applications and study their code. Analyze how they have implemented things. Figure out their database schema.

This is very useful for PHP beginners who have no problem grasping the syntax but struggle on implementing and developing websites and web applications.

Be flexible in your approach

Do not give into preconceived notions. Be flexible in adopting technologies and programming techniques. Don’t form too strong opinions against OOP, templates and frameworks. One never knows when a particular technology may become the main requirement of one of your projects.


Source:phpsense.com

Wednesday, November 26, 2008

PHP curl

'cURL' is the name of the project. The name is a play on "Client for URLs", originally with URL spelled in uppercase, it obvious it deals with URLs. The fact it can also be called 'see URL' also helped, it works as an abbreviation for "Client URL Request Library" or why not the recursive version: "Curl URL Request Library".

The CURL project produces two products:

libcurl

A free-and-easy-to-use the Client-side URL transfer library, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, FILE and LDAP. Libcurl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, kerberos, HTTP form based upload, proxies, cookies, user+password authentication, file transfer resume, http proxy tunneling and more!

libcurl is highly portable, it builds and works identically on numerous platforms, including DOS ,Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, AIX, HPUX, IRIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare and more.

libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported and fast.

curl

curl is a command line tool for getting or sending files using URL syntax.

Since curl uses libcurl, it supports a range of common Internet protocols, currently including HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, LDAP, DICT, TELNET and FILE.

We pronounce curl and cURL with an initial k sound: [kurl].

Test with the following PHP code:

$url = "http://informativesite.blogspot.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$returned = curl_exec($ch);
curl_close ($ch);
echo $returned;