PHP

An Idea on Browser Cache

Web browsers and proxy servers (something ISPs and other corporations create to improve network efficiency) habitually cache Web pages. Caching a page is a matter of storing its content (or part of its content, like an image or video) and then providing that stored version, rather than the version on
the server, when a request is made.

For most end users, this is not a problem. In fact, they may not be aware that they are receiving an outdated version of a page or image. But if, while developing a site, you’ve struggled to get your Web browser (let’s face
it: the likely culprit is Internet Explorer) to recognize changes you know you’ve made in a page, then you’ve seen the dark side of caching. With your dynamic, PHP-driven sites, sometimes you want to make certain that end users are getting the most up-todate version of your pages.

Caching—both in Web browsers and proxy servers—can be affected using PHP’s header() function. There are four header types involved:

An introduction to using Curl

This utility, which stands for client URLs (and is also written as just curl or
Curl), is a command-line tool for working with URLs. With cURL you can access Websites, FTP files, and do much, much more.PHP can use cURL via the shell_exec() and other system functions. But PHP also supports libcurl, a cURL library.

The process starts by using curl_init(), providing this function the name of the URL being accessed:

$curl = curl_init(‘www.example.com’);

The value returned by the function should be assigned to a variable, which will act as a pointer or a handle to the transaction. Next, the curl_setopt() function is used (a lot) to set any options. The syntax is:

curl_setopt($curl, CONSTANT, value);

Unfortunately, there are way too many options to even provide a subset here. In
the following example I’ll highlight a handful of them. If you take to cURL, check out the PHP manual for the full list of settings.

PHP Interview Questions

1. What's PHP
The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.

2. What Is a Session?
A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.
There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.
Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

3. What is meant by PEAR in php?

Answer1:

Using Perl Code in PHP

PHP perl extension is available to allow the usage of perl code in PHP.

The perl extension is used to load and execute perl files, evaluate perl code, access perl variables, call perl functions, instantiate perl objects, access properties of perl objects, call methods of perl objects.

PHP's perl extension is available from the PECL web site at http://pecl.php.net/package/perl. The latest development version can be obtained with the following CVS command:

$ cvs -d :pserver:cvs.php.net:/repository co pecl/perl

If you have a full perl installation, the extension will work with it. If you don't have perl on board, you can still communicate with the perl interpreter through PHP by putting a copy of perl58.so or perl58.dll somewhere PHP can find it (in the PHP directory or in your system path).

To access the perl interpreter from PHP, you must first create an instance of the Perl class.

$perl = new Perl();

Checking File Permissions In PHP

Since script can only read and write files when the PHP interpreter has permission to do so. You don't have to cast about blindly and rely on error messages to figure out what those permissions are, however. PHP gives you functions with which you can determine what your program is allowed to do.

To check whether a file or directory exists, use file_exists( ). Here is an example which uses this function to report whether a directory's index file has been created.

Checking the existence of a file

<?php
if (file_exists('/usr/local/htdocs/index.html')) {

    print "Index file is there.";

} else {

    print "No index file in /usr/local/htdocs.";

}
?>

To determine whether your program has permission to read or write a particular file, use is_readable( ) or is_writeable( ). Here is an example which checks that a file is readable before retrieving its contents with file_get_contents( ).

Testing for read permission

<?php

Cumulus Tag Cloud

Kiran Says

I love work environment which is:

Informal yet professional
Demanding yet rewarding
Challenging yet inspiring
Mediocrity is not an option
Having fun is serious business
Making mistakes is human
Forgiveness is Company Policy

Travelling Sucks