Kiran's blog

Using COM with PHP

Added in PHP 4 is support for COM on Windows operating systems. COM, which
stands for Component Object Module, is a technology developed by Microsoft to control its applications via a programming language, notably Visual Basic. It is related to other Microsoft technologies such as OLE (Object Linking and Embedding) and ActiveX.

Microsoft has defined every function and attribute that an application—such as Word or Excel—has as an object with methods and properties. Using the proper notation, you can then control the application with Visual Basic or, in this case, PHP. You begin by creating a new object using the name of the application and PHP’s com() function.

$word = new COM(‘word.application’);

You can set the application to run either visibly on the computer or invisibly by setting the Visible value (this step is not required).

$word->Visible = 1; // Visible

Once the application is running, you begin by creating a new document.

Establishing a cron

A cron is a service on Unix servers that allows tasks to be scheduled and executed automatically. The cron application runs constantly and will, according to instructions, carry out its orders. These orders are stored in a file called crontab. This file is a to-do list that contains lines that might look like this:

30 22 * * * lynx --dump http://www.kiran.org.in > /dev/null

The crontab format dictates that each line contain six fields separated by spaces or tabs. The first five fields represent, in order, minutes, hours, days, months, and day of the week (from 0 to 6, with 0 being Sunday).
Notice that you can specify the day of operation as either a day of the month (1–31) or a day of the week (Sunday through Saturday), the latter being date-indifferent.

Tips on Web Page Caching

■ Note that caching is, in theory, a very good thing, designed to minimize unnecessary server requests. If properly controlled, caches are great for both the server and the client.

■ If you have cURL installed on your system, you can run this command to see a
page’s headers:
curl --head http://www.example.com/page.php

■ If your applications make use of sessions, you can adjust session caching with the session_cache_limit() function. See the manual for more information.

■ Page caching can also be affected using the META tags, placed within an HTML
document’s head. This may not work as reliably with some browsers as the
header() method.

■ Client/server performance can also be improved—for large scripts—using Zlib
output compression or the function ob_gzhandler() . See the PHP manual
for more on both.

Server-Side Caching

There is an alternative type of caching you can use to affect the client/server

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.

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