Wednesday, December 19, 2007

Populate bookstore db in sun's J2EE5 sample

In order to populate the database using "ant create-tables" command, you need to follow the steps below:
By default, sun's application server is installed in C:\Sun\AppServer. If using a non-installation package, the j2ee server home directory could be C:\Sun\SDK.
In the tutorial, there is a build.properties.sample file in the javaeetutorial5/examples/bp-project.
1. Copy that file and rename it to build.properties.
2. In the build.properties, edit the javaee.home, javaee.tutorial.home to match your environment.
3. Uncomment the AS_ADMIN_PASSWORD and specify your application server admin password.

Sunday, December 16, 2007

J2EE Review 1: RMI implementation

1. Declare Remote Interface
For example:
import java.rmi.*;
public interface MyRMIServer extends java.rmi.Remote{...}

Note that methods in the interface must throw RemoteException.
2. Implement Remote Interface
import java.rmi.*;
import java.rmi.server.*;
public class MyRMIServerImpl extends UnicastRemoteObject implements MyRMIServer{...}
3. Generate Stub (and Skeleton)
Use rmic command, not that after Java 1.2, no skeleton will be generated by default.
If you want to get the source file for the stub, use the keepgenerated flag.
rmic MyRMIServerImpl -keepgenerated
4. Register Remote Object
The process of registering an object with the RMI registry is called binding. There are 2 methods in the java.rmi.Naming class can bind an object to the registry. The bind() methods throws the AlreadyBoundException if the binding already exists, while rebind() method replaces any existing registry entry with the new one. unbind() is used to remove an object from the registry.
4a. Start rmi registry
use the command line
rmiregistry
to start registry on the default RMI port 1099.
use the command
rmiregistry 5555
to start the registry on port 5555
4b. Register object
import java.rmi.*;
public class StartMyRMIServer{
public static void main(String[] args){
try{
MyRMIServerImpl mrsi=new MyRMIServerImpl();
Naming.rebind("rmi://localhost:5500/MyRMIService",mrsi);
System.out.println("My RMI Service is waiting for the requests on port 5500 ...");
}catch(Exception ex){
ex.printStackTrace();
}
}
}
4c. Alternative: Combining 4a and 4b using the following code
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
public class StartMyRMIServer{
public static void main(String[] args){
try{
LocateRegistry.createRegistry(5500);
MyRMIServerImpl mrsi=new MyRMIServerImpl();
Naming.rebind("rmi://localhost:5500/MyRMIService",mrsi);
System.out.println("My RMI Service is waiting for the requests on port 5500 ...");
}catch(Exception ex){
ex.printStackTrace();
}
}
}
5. Create RMI Client
import java.rmi.*;
import java.util.Vector;
public class MyRMIClient{
public static void main(String[] args){
try{
if(System.getSecurityManager()==null){
System.setSecurityManager(new RMISecurityManager());
}
MyRMIServer myServer=(MyRMIServer)Naming.lookup("rmi://localhost:5555/MyRMIService");
}
......

6. Create a policy file
Policy files contain permissions granted to users of this application. Here's an example of security.policy.
grant{
// Allow the client to connect to any port above 1024
permission java.net.SocketPermission "*:1024-", "connect";
};
7. Run RMI Client
java -Djava.security.policy=security.policy MyRMIClient

Thursday, October 18, 2007

Java stack size

Java stack size can be set using the command option with Java. It takes effects on all the threads of a Java process.
"Insufficient stack size"
More information on how to set is is available in:jvm-tuning

Oracle bind variables

A good introductory source to Oracle bind variables:
Bind variables - The key to application performance

Thursday, October 04, 2007

RosettaNet

Not much introductory material related to RosettaNet in Internet. Here's a good article: Introduction to RosettaNet .

RosettaNet Overview (PDF): RN Overview .

Tuesday, July 31, 2007

Monitor the SQL statement being executed in Oracle

There are several way to monitor the sql statement being executed in Oracle database.
We can do it through a client side monitoring tool, or some jdbc debugging drivers.
There is one thing we can do in the server side, and the following statement will do the trick:

select SQL_TEXT, SQL_ID, FIRST_LOAD_TIME, LAST_LOAD_TIME, LAST_ACTIVE_TIME, ELAPSED_TIME, MODULE
from v$sql where MODULE like '%JDBC Connect Client%'
order by FIRST_LOAD_TIME desc


More information about v$sql is available at v$sql reference .

For the implementation part of an Oracle client, we can use d, t, and ts. The specification about them is available at Time and Date literal .

Saturday, July 14, 2007

Character Sets and Collations in MySQL

A character set is a set of symbols and encodings. A collation is a set of rules for comparing characters in a character set.

The MySQL server can support multiple character sets. To list the available character sets, use the SHOW CHARACTER SET statement.
mysql> SHOW CHARACTER SET;
Any given character set always has at least one collation. It may have several collations. To list the collations for a character set, use the SHOW COLLATION statement.
mysql> SHOW COLLATION LIKE 'latin1%';

Every database has a database character set and a database collation. The CREATE DATABASE and ALTER DATABASE statements have optional clauses for specifying the database character set and collation:
CREATE DATABASE db_name
[[DEFAULT] CHARACTER SET charset_name]
[[DEFAULT] COLLATE collation_name]


ALTER DATABASE db_name
[[DEFAULT] CHARACTER SET charset_name]
[[DEFAULT] COLLATE collation_name]


Example:
CREATE DATABASE db_name CHARACTER SET latin1 COLLATE latin1_swedish_ci;

The database character set and collation are used as default values if the table character set and collation are not specified in CREATE TABLE statements. They have no other purpose.

In order to check teh character set and collation for the databases, tables and columns, you can go to the information_schema database, and check the table called SCHEMATA.
mysql> SELECT * FROM SCHEMATA;

Synonyms in Oracle

What is synonym in Oracle? What's it used for?
Here's a good article about it: Synonyms in Oracle .

Installing and testing MySQL Server 5.0.45

Instructions for installations are available in Install MySQL on a RH machine .
Basic commands include:

shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz tar xvf -

shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &


If mysqld is currently running, you can find out what path settings it is using by executing this command:
shell> mysqladmin variables
Or:
shell> mysqladmin -h host_name variables

Another good instruction on installing MySQL Server is available here.

Tuesday, June 26, 2007

Configure MQ server (5.3) to accept client connections on Windows platform

a. Start your queue manager by using the strmqm command.
b. Type the following command to start the runmqsc program:
runmqsc [QMNAME]
c. Define a sample channel called JAVA.CHANNEL by issuing the following command:
DEF CHL(’JAVA.CHANNEL’) CHLTYPE(SVRCONN) TRPTYPE(TCP) MCAUSER(’ ’) + DESCR(’Sample channel for WebSphere MQ classes for Java’)
d. Start a listener program with the following commands:
runmqlsr -t tcp [-m QMNAME] -p 1414

Monday, June 25, 2007

Basic Websphere MQ Command

Lately I've been involved in solving a MQ problem. Not really familiar with this product, so I'll put down some basic commands here for later reference.
(1) Create a queue manager. Example:
crtmqm -q yelei.queue.manager
(2) Start the queue manager. Example:
strmqm yelei.queue.manager
(3) Launch MQSC console:
runmqsc
(4) Define a local queue in the console:
define qlocal yelei.queue
(5) Exit MQSC:
end
(6) Put a message on the queue. Example:
amqsput yelei.queue
(7) Get a message from the queue. Example:
amqsget yelei.queue

Tuesday, June 12, 2007

oracle command examples

Sometimes it takes me a while to look for the SQL command I need in Oracle. Just record something I got.
(1) displaying tables in a schema:
select * from user_tables;
(2) displaying column information for a relation:
describe wms_notif;
(3) check entries without corresponding entries in the other table:
select DG_ANALYSIS_MONITOR_ID from DG_ANALYSIS_MONITORwhere DG_ANALYSIS_MONITOR.DG_ANALYSIS_MONITOR_ID not in (select BAM_MONITOR_LAST_READING.DG_ANALYSIS_MONITOR_ID from BAM_MONITOR_LAST_READING);

Thursday, June 07, 2007

check local machine IP

I only got the loop address 127.0.0.1 when using "hostname -i".

So it's better to use "/sbin/ifconfig -eth0" with the root account.

Or "ip addr show".

Check this out: http://www.pixelbeat.org/cmdline.html

Issue related to Fedora 7 displaying mouse cursor

Sometimes with a fresh installation of Fedora, you'll not be able to see the mouse on the desktop. Here is an url invisible cursor in Fedora , which gives the information about how to solve it.

If you have just installed Fedora (or any other distro which uses xorg) you may have encounter the problem by which your cursor works, but you just can't see i: that is you have no cursor. The solution is fairly simple.
Open for editing the xorg config file as root. It is usually located at /etc/X11/xorg.conf . Locate the device section of the configuration file.
Add the following entry into the device section (on its own line):
Option "SWcursor" "True"
Restart the computer (or just xorg). Your problem should now be gone.

Friday, May 25, 2007

Checking out all the running process in Linux system

Everybody know that "ps" command can be used to find out the running processes in a Linux OS. But "top" is not so well-known as "ps". Sometimes it's a much better way to view all the processes, because it displays the information DYNAMICALLY!
I happened to find the article today: Show all running processes in Linux .

Here's the content:
ps command gives a snapshot of the current processes. If you want a repetitive update of this status, use top command.

Task: Use ps commandType the following ps command to display all running process
# ps aux less

Where,
-A: select all processes
a: select all processes on a terminal, including those of other users
x: select processes without controlling ttys

Task: see every process on the system
# ps -A
# ps -e

Task: See every process except those running as root
# ps -U root -u root -N
Task: See process run by user vivek
# ps -u vivek

Task: Use top command
The top program provides a dynamic real-time view of a running system. Type the top at command prompt:
# top
To quite press q for help press h.

Task: display a tree of processespstree shows running processes as a tree.
The tree is rooted at either pid or init if pid is omitted. If a user name is specified, all process trees rooted at processes owned by that user are shown.

Task: Lookup process
Use pgrep command. pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to screen.
For example display firefox process id:
$ pgrep firefox
Following command will list the process called sshd which is owned by root user.
$ pgrep -u root sshd

Say hello to htop
htop is interactive process viewer just like top, but allows to scroll the list vertically and horizontally to see all processes and their full command lines. Tasks related to processes (killing, renicing) can be done without entering their PIDs.
To install htop type command:
# apt-get install htopor
# yum install htop
Now type htop to run the command:
# htop

Monday, April 16, 2007

User Restriction on remote SSL connection

Here's the original source: OpenSSH Root user account restriction - revisited .

-- “I need something that allows me to say: allow any users except root from anywhere, and root only from localhost. (over ssh session)”.

PAM offers very powerful authentication control.
You need to use the pam_access PAM module, which is mainly for access management. It provides login access control based on Login names, Host or domain names, Internet addresses, or network IP numbers, Terminal line names etc.

Why pam_access matters?
On a production server, authorized login can come from any networked computer. Therefore, it is important to have tight control over users who are allowed to connect server via OpenSSH server.

How do I configure pam_access?
You need to edit following files:
/etc/pam.d/sshd - Linux PAM configuration file.
/etc/security/access.conf - By default rules for access management are taken from configuration this file. When someone logs in, the entry in this scanned and matched against rule. You can specify whether the login will be accepted or refused to user. General syntax is as follows:
permission : username: origins
Where,
permission : Permission field should be a “+” (access granted) or “-” (access denied)character.
username : Linux system username/login name such as root, yelei etc. You can also specify group names. You can also use special keywod ALL (to match all username).
origins : It is a list of one ore more tty names, host name, IP address, domain names that begin with . or special key words ALL or LOCAL Let us say you want to allow user root and yelei login from IP address 202.54.1.20 only.

Open file /etc/security/access.conf, and append following line:
-: ALL EXCEPT root yelei:202.54.1.20
Save the file and Open /etc/pam.d/sshd file, and append following entry:
account required pam_access.so
Save and close the file.

Thursday, April 12, 2007

Reload httpd.conf in Apache http server

Before reloading the httpd.conf file, you'd better use "apachectl configtest" to check if the conf file is valid.
According to "man apachectl":
apachectl restart - Restarts the Apache daemon by sending it a SIGHUP. If the daemon is not running, it is started. This command automatically checks the configuration files via configtest before initiating the restart to make sure Apache doesn't die.
apachectl graceful - Gracefully restarts the Apache daemon by sending it a SIGUSR1. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. A side effect is that old log files will not be closed immediately. This means that if used in a log rotation script, a substantial delay may be necessary to ensure that the old log files are closed before processing them. This command automatically checks the configuration files via configtest before initiating the restart to make sure Apache doesn't die.
The 'graceful' would only be required if you are updating an active in-service machine and you do not want to interupt active connections.

Thursday, March 15, 2007

Non-secure item in a webpage accessed through HTTPS

Just got a good article about handling the pop-up message box "This page contains non-secure items, would you like to display those items?" from Scott Yang's playground .

Here's an excerpt from the article:

At work, the web application that I’ve been developing has always had this problem over a secure SSL link. On certain pages, before the document is fully loaded, a dialog box will popup telling me that “This page contains non-secure items, would you like to display those items?”. Whether I choose ‘Yes’ or ‘No’ does not really make a difference, and the application can still be executed perfectly. However, this dialog box is really annoying to the point that many people in the office has turned off this checking in their Internet Explorer preferences.

Solution:
Make Sure You Have SRC Attribute In Your IFRAME!
We have quite a few IFRAME tags in our code, either pre-generated or appended to the document using DOM. Many of them are pointing to a relative URL when they are created, however, some of them are just created as hidden place holders. They are used in DHTML to replace some DIV code because DIV does hover well above the editing widgets. They are created without a SRC attribute, because their documents are created on the fly! Because the document does not have an URL, Internet Explorer gets confused and thus yield a warning on displaying non-secure items.
It ends up as an easy fix - just create thus IFRAME’s with SRC pointing to a dummy page using a relative URL.

WYSIWYG script error in Joomla

When WYSIWYG editor is used in a Joomla site and you use subdomains, you should be careful with setting your live site global variables, because the Joomla page uses $mos_Config_live_site to load the java script of WYSIWYG editor.
In order to protect you against potentially malicious scripting. IE only allows script from your domain to run on it's page. If you didn't specify the correct subdomain in the configuration.php file for your joomla site, you may have the following error:
Error: Access is denied.
Normally, in linux system, your website files will be located in the "www" folder, whose contents correspond to the "www.yoursite.com" domain name. So if you install joomla in a subdirectory called "myJoomla" under "www", you should configure $mos_Config_live_site="http://www.yoursite.com/myJoomla" for your IE users.
According to Joomla Forum , this problem does not exist for firefox users because firefox considers folder-domain and sub-domain to be matched.

Tuesday, March 13, 2007

how to back up mysql database for a website?

Just got a good article about how to back up MySQL database using phpMyAdmin, which is very useful when maintaining a website.
Please click " Backup and Importing Joomla Database " (from GeekTips.net) to get the detailed information.

Monday, March 12, 2007

Configuring Internet Connection for vmware

Today when I was working on my SUSE vmware, I made a little change with the network configuration. But what I didn't realize was that it would cause the failure of internet connection. The problem turned out to be even worse because vmware network connection was configured through vmware softwares not the guest OS, which means I could not revert the modification in SUSE.
After several attempts that didn't resolve this issue, I had to power off the vmware because the OS was not useful to me if there was no internet connection. But at that moment, I happened to see that there was the other vmware image in my system, which has the internet connection. So I compared the 2 vmwares' .vmx files, and found out there was one major difference in the network configuration:
ethernet0.connectionType="bridged"
When I changed the network configuration in SUSE, it would be modified to ethernet0.connectionType="nat", which caused the disconnection to the network.

Wednesday, March 07, 2007

Different oracle JDBC drivers

This information is from Oracle, I collect it here just for convenience.

The [ORACLE_HOME]/jdbc/lib directory contains:
- classes111.zip & classes111.jarClasses for use with JDK 1.1.x. It contains the JDBC driverclasses except classes necessary for NLS support in Object andCollection types.
- nls_charset11.zip & nls_charset11.jarNLS classes for use with JDK 1.1.x. It contains classes necessaryfor NLS support in Object and Collection types.
- classes111_g.zip & classes111_g.jarSame as classes111.zip, except that classes were compiled with"javac -g" and contain OracleLog traceing code.
- classes12.zip & classes12.jarClasses for use with JDK 1.2.x. It contains the JDBC driverclasses except classes necessary for NLS support in Object andCollection types.
- nls_charset12.zip & nls_charset12.jarNLS classes for use with JDK 1.2.x. It contains classes necessaryfor NLS support in Object and Collection types.
- classes12_g.zip & classes12_g.jarSame as classes12.zip, except that classes were compiled with"javac -g" and contain OracleLog tracing code.
- classes12dms.jarSame as classes12.jar except contains additional code to supportOracle Dynamic Monitoring Service.
- classes12dms_g.jarSame as classes12dms.jar except that classes were compiled with "javac -g" and contain OracleLog traceing code.
- ojdbc14.jarClasses for use with JDK 1.4. It contains the JDBC driverclasses except classes necessary for NLS support in Object andCollection types. Use nls_charset12.jar if needed.
- ojdbc14_g.jarSame as ojdbc14.jar except that classes were compiled with"javac -g" and contain OracleLog tracing code.
In general, .zip and .jar are identical except for theformat of the archive. Both the .zip and .jar formats are providedfor JDK 1.1 and JDK 1.2. Only .jar files will be provided for JDK1.4 and beyond. So far, there is no need for JDK 1.3 classes files;use classes12.jar with JDK 1.3.
Note that most of the classes pertaining to specific character setssupport in Oracle Object and Collection types are separated from thebasic zip/jar files. These NLS classes are packaged into theextension zip/jar files. This allows the user to include the NLSclasses only if necessary. Please refer to the "NLS Extension ZipFiles (for client-side only)" section for further details. Alsonote that the nls_charset files are much smaller than in priorreleases. These .zip/.jar files now contain a more compactrepresentation of the conversion information rather than actual.class files.
[ORACLE_HOME]/lib directory contains libocijdbc9.so, libocijdbc9_g.solibheteroxa9.so and libheteroxa9_g.so (on Solaris), which are theshared libraries used by the JDBC OCI driver.
[ORACLE_HOME]/jdbc/doc/javadoc.tar contains the JDBC Javadoc. Thisrelease contains a beta release of the Javadoc files for the publicAPI of the public classes of Oracle JDBC.
[ORACLE_HOME]/jdbc/demo/demo.tar contains sample JDBC programs.All of the sample programs have been rewritten to use JDK 1.2 and thenew Oracle standard sample schemas. They no longer use the old standbyscott/tiger schema. These new sample schemas are much more featurerich and so make it easier to demonstrate Oracle features. All Oraclesample code and training will be using these new schemas verysoon. Most already does.

Thin Driver:
the thin JDBC Driver can be used to develop both Java applets and Java applications. Since it is written completely in Java it is downloadable and therefore can be used with Java applets. It can also be used for Java applications but only if you are using TCP/IP. Unlike the JDBC OCI driver, the Thin JDBC driver only works with TCP/IP-based networks. Users who are running applications on non-TCP/IP networks are encouraged to use the JDBC OCI driver.

OCI Driver:
the JDBC OCI Driver is not designed for use with Java applets but designed for client-server Java applications and Java-based middle tiers. The Thin JDBC Driver is targeted for Java applet developers. The JDBC OCI driver transforms calls from Java to C [since the driver must use a layer of C in order to make calls to the OCI], the driver is written in a combination of Java and C which precludes it from being downloadable. Further, JDBC OCI driver also requires installation of the OCI libraries, SQL*Net, CORE libraries and other required support files on the machine on which the JDBC driver is installed i.e. on each of the client machines or the middle-tier Java application server.

Access Oracle JDBC FAQ.

Tuesday, March 06, 2007

How to view all the oracle tables in a schema?

In MySQL, we can use commands like "show tables" to view all the tables in the current database. However, when I tried to find such a command in the Oracle documentation, i didn't succeed.
I'm not should if there is such a command.
But if you want to display all the oracle tables, here's the sql statement you should use:
SELECT table_name FROM tabs;

Saturday, February 10, 2007

Step-by-Step Creation of Vmware images

Sometimes a different OS (other than the one you are running on your machine) is needed for testing purpose. Vmware technology provides a convenient way (not so convenient, but it's easier than getting another machine and install, or install another OS on local machine) to do this.
For example, by using vmware, there are 2 steps to use a Linux system like Suse, on Windows OS:
(1) Making an image of the target Linux system (guest OS).
(2) Use vmware player (which is available in vmware.com) to run the image.

But how to make the image of the guest OS? Here are several steps:
(1) You must ensure that you have enough space required by the guest OS. You should get VMWare Disk Image (a VMDK file) and a VMX file in order to describe the virtual machine.
(2) These files are downloadable in Forever For Now Blog .
(3) Put these 2 files in a directory and edit the vmx file to set up the guest OS description and installation image.
(4) Use vmplayer to run the image.
(5) The installation of the guest OS will automatically starts......
The detailed installation guide can be found at vmplayer documentation site.

Friday, February 09, 2007

Problems when installing pear

I got the following error when I first tried to install PEAR components:
Cannot find module (IP-MIB): At line 0 in (none)
Cannot find module (IF-MIB): At line 0 in (none)
Cannot find module (TCP-MIB): At line 0 in (none)
Cannot find module (UDP-MIB): At line 0 in (none)

.......
I googled this error, every expert says there's a configuration error. Yes, there must be a configuration issue. That is so obvious! But, WHERE? Where does this fucking configuration issue reside?
I checked the php.ini file, but I didn't get many clues at first. After a while, I recalled that the php.ini file is created by renaming the default "php.ini-dist" file. There are some unnecessary entries in the end of the file which led to the above error. After deleting all of them, everything works fine.
However, another problem appeared, which was like:
PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar/PEAR/Command.php on line 268
......
This was also a strange error. But still, not much information in the documentation related to this! The solution was:
(1) go to the site: http://go-pear.org/ , read the instructions;
(2) you'll find the following command for windows:
C:\php5>php -r "readfile('http://pear.php.net/go-pear');">go-pear
C:\php5>php go-pear

The it's all solved! It took me almost one hour due to lack of documentation.

Thursday, February 08, 2007

PHP parameter passing

PHP seems to adopt some Java concepts/rules, especially in OOP, such as handling objects/instances.
Normally, php data is passed by value. In PHP5, php data of primitive data types like int, float, etc is still passed by value. But the object is passed by reference. Saying that "the object is passed by reference" is not totally true. Actually, the object handle is still passed by value.
This is exactly the same case as that in Java.
PHP also has features like method pointer, which is introduced by C/C++.
Hope php keep its good performance while using some advanced programming ideas.

Wednesday, February 07, 2007

Usage of register_globals in php

The option register_globals is used to register session variables as regular global variables in the current page as soon as the sessionis discovered. By default, this option is turned off for php 4.2 and later versions.

Several safety issues in php

(1) In PHP there is now a very easy mechanism to disable the capabilityto file-write. This is a great idea especially if your site is entirely database-driven, inwhich case you don’t have any legitimate need to write to the filesystem with PHP anyway.To disable file writing, simply add fwrite to the list of disabled functions in php.ini:
disabled_functions = “fwrite”
If you don’t use php.ini and need to set this value in Apache httpd.conf, remember that it requires a php_admin_value flag (rather than php_value):
php_admin_value disabled_functions=”fwrite”

(2) Many of functions related to file operations are dangerous. Because they duplicate functions that can and should be performed from the local system, they can be a cracker’s bonanza without providing much value to legitimate users. Strongly consider disabling them using PHP’s disable_functions directive!

(3) Remember that although the Web server (and client-side languages such as JavaScript) canonly act on files located under the document root, PHP can access files at any location in the file system—including those above or entirely outside the Web server document root—aslong as the file permissions and include_path are set correctly. For instance, if your Webserver document root is located at /usr/local/apache/htdocs, Apache will be able toserve only files from this directory and its subdirectories, but PHP can open, read, and writeto files in /usr/local, /home/php, /export/home/httpd, or any other directory thatyou make readable and includable by the PHP and/or Web server user.

Monday, February 05, 2007

Difference between $PHP_SELF and $_SERVER['PHP_SELF']

Just got a good article about this:
Understanding $_SERVER[’PHP_SELF’], $PHP_SELF, $_SERVER[’REQUEST_URI’] and $_SERVER[’SCRIPT_NAME’] in PHP and when to use what .
Basically, $PHP_SELF is deprecated and should not be used because it will not work without register_globals being enabled. As of PHP 4.2.0 the default for the PHP directive register_globalswent from on to off.

Saturday, February 03, 2007

New Blogger sucks

Almost everytime I click buttons in new version blogger to save my settings and publish my posts, it'll display an error.
Now I have to use email to blogging.
I hope this issue be resolved soon.
It really SUCKS!
(This is an email-publishing test)

Thursday, February 01, 2007

PHP Apache tips

(1) How to log errors in PHP instead of displaying them on the page?
Use the following lines in php.ini:
; Print out errors (as a part of the output).
information.display_errors = off
; Even when display_errors is on, errors that occur during PHP's startup; debugging.display_startup_errors = Off
; Log errors into a log file (server-specific log, stderr, or error_log (below));
sites.log_errors = On
; Set maximum length of log_errors.
log_errors_max_len = 1024
; Do not log repeated messages.
ignore_repeated_errors = Off
; Ignore source of message when ignoring repeated messages.
ignore_repeated_source = Off
; Log errors to specified file.
error_log = "logs/errors.log"
(2) How to find backend SQL errors?
Set the following line in php.ini:
; Trace mode. When trace_mode is active (=On), warnings for table/index scans and SQL-Errors will be displayed.
mysql.trace_mode = On

(3) How to avoid exposing index structures for a folder?
Set the following lines in httpd.conf:
## DirectoryIndex: sets the file that Apache will serve if a directory is requested.

DirectoryIndex index.php

In such a way, request for a directory will be redirected to the file "index.php".
(4) How to use logging in Apache server?
Use the following 2 settings:
## ErrorLog: The location of the error log file.
ErrorLog logs/error.log
## LogLevel: Possible values include: debug, info, notice, warn, error, crit, alert, emerg.

LogLevel warn
(5) How to do directory-level access configuration for Apache Http Server?
Here's an example:

Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

Details can be found in http://httpd.apache.org/docs/2.2/mod/core.html#options .

Wednesday, January 31, 2007

Configure MySQL with PHP

Product version: PHP5 (Non-installed version for windows), MySQL5 (Non-installed version for windows).
Steps:
(1) Use php.ini-recommended as the default ini file by renaming it to php.ini.
(2) In the development environment, it's useful to set display_errors = on. When moving the web application to production, this switch should be turned off.
(3) Check the document root in the following line: doc_root ="C:\Program Files\Apache Software Foundation\Apache2.2\htdocs" .
(4) Specify the loadable module directory extension_dir = "C:\php5\ext" .
(5) Enable php_mysql.dll inside of php.ini by removing semicolon from the line ;extension=php_mysql.dll .
(6) PHP needs access to the MySQL client library. A file named libmysql.dll is included in the Windows PHP distribution and in order for PHP to talk to MySQL this file needs to be available to the Windows systems PATH. So add "C:\php5\" to PATH environmental variable.
(7) Specify upload_tmp_dir and session.save_path if necessary.
(8) Copy some extension pointers in the orginal php.ini file into the new php.ini file.

Simplest way to configure Apache Http Server with PHP

Product Version: Apache Http Server 2.2, PHP 5.
Non-install version of php is used.
Modify file /conf/httpd.conf by adding the following lines:

LoadModule php5_module "C:/php5/php5apache2_2.dll"
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php5"

C:/php5 is the location where php5 is installed.

Modify php.ini by specifying:

doc_root ="C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"

Wednesday, January 10, 2007

Interoperability between oracle jdbc driver and oracle database

There are some data type mapping issues when using oracle jdbc driver 10 with oracle 9i database, which is explained on Oracle JDBC FAQ . Old version mapping can also be done by setting the value of "V8Compatibility" to true.

Interesting stuff about portlet development

Concepts of portal and portlet development are quite well explained in the following articles:
Introducing Portlet Specification 1 ,
Introducing Portlet Specification .