Monday, February 28, 2011

How to create VIRTUAL HOST in APACHE

We need to modify Apache configuration file httpd.conf for creating virtual host. At the end of the file we need to place below sample code.

<VirtualHost www.sunwaretech.net>
ServerAdmin admin@sunwaretech.net
DocumentRoot /home/apache/share/htdocs/hostedsites
ServerName www.sunwaretech.net
ErrorLog /home/apache/logs/error/hostedsites/error_log
TransferLog /home/apache/logs/access/hostedsites/access_log
</VirtualHost>


Simply we need to mention domain name, server admin email address, document root, server name and log files path.

Difference between CHAR and VARCHAR datatypes

CHAR is a fixed-length character data type where as VARCHAR is a variable-length character data type.
CHAR should be used for storing fixed length character strings. String values will be space/blank padded before stored on disk. If this type is used to store variable length strings, it will waste a lot of disk space.
 
Where to use:
You can use CHAR when the data entries in a column are expected to be the same size.
You can use VARCHAR when the data entries in a column are expected to vary considerably in size.

Sunday, February 27, 2011

How to use PHP CURL

Below is the sample basic code for using the curl.

<?php

 // create a new cURL resource
 $ch curl_init();
// set URL and other appropriate options

 $options = array(CURLOPT_URL => 'http://www.example.com/',
                 
CURLOPT_HEADER => false
                
);
curl_setopt_array($ch$options);


//curl_setopt($ch,CURLOPT_URL,'http://google.com'); You can use this line rather than the above two lines for initializing the URL.

 // grab URL and pass it to the browser 
curl_exec($ch);
// close cURL resource, and free up system resources

 curl_close($ch);

?>


Below is the explanation of the above functions
  • curl_init method used to initiate curl object.
  • curl_setopt method for setting options to curl object
  • CURLOPT_URL = Curl Option URL, here we need to set the remote server URL
  • curl_exec method will execute the curl object.
  • curl_setopt_array method used to send multiple parameters as an array.
Start make use of this cURL features and feel the joy of it.

PHP CURL Installation in Windows and Linux

PHP has a very powerful library to fetch data from remote servers which is nothing but CURL. It stands for Client URL.

PHP must be compiled with curl library to make use of these libraries.

In Linux, you need to compile PHP --with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories. In include folder there should be a folder named curl which should contain the easy.h and curl.h files. It should be a file named libcurl.a located in the lib folder. From PHP 4.3 you can configure PHP to use cURL for URL streams -- with-curlwrappers.

For Windows, go to PHP environment path, WINDOWS/System32 folder is the default one for windows XP operating system. You must copy php_curl.dll to this folder.

In php.ini file remove ";" from the line extension=php_curl.dll

Restart Apache services. Then cURL will be enbled