Categories
common

phpCodeBeautiful与editplus结合改进

有人提议使用phpCodeBeautiful的命令行,看这里:超链接地址http://club.phpe.net/index.php?act=ST&f=2&t=3701

在此基础上俺进行了修改,适合自己使用:

pcb.bat

代码片段:


set phpcb_path="F:Program FilesphpCB"
%phpcb_path%phpCB.exe -space-after-if -space-after-switch -space-after-while -space-before-start-angle-bracket -space-after-end-angle-bracket -glue-amperscore -change-shell-comment-to-double-slashes-comment -force-large-php-code-tag -force-true-false-null-contant-lowercase --comment-rendering-style PEAR -align-equal-statements-to-fixed-pos -indent-with-tab -optimize-eol -align-equal-statements --padding-char-count 1 %1 > %TEMP%phpcbTemp.php
move /Y %TEMP%phpcbTemp.php %1
Categories
common php

利用xampp将apache和tomcat整合

xampp可以将apache+php+mysql+phpmyadmin一次性自动安装完成,很适合快速搭建测试服务器.它也提供了tomcat的插件,可以很快的搭建jsp开发环境.

以俺在winxp安装为例:
1.在http://www.apachefriends.org/en/xampp-windows.html下载XAMPP,推荐下载EXE (7-zip) 打包的xampp,这个个头比较小,部署的时候也比较灵活.
2.在同一页面下载tomcat插件,同样选择7-zip
3.解压xampp的压缩包到你指定的目录,例如d:xampp
4.运行setup_xampp.bat,至此,xampp安装完成
5.解压tomcat插件到xampp目录,运行setup_java.bat即可将tomcat插件安装完毕

现在一个php+jsp的快速开发环境已经搭建好了.

附上tomcat的配置(详细信息见Readme):
Tomcat Server Home = .xampptomcat
Tomcat URL = http://localhost:8080
Tomcat Doc Root = .xampptomcatwebapps

JSP example Root = .xampptomcatwebappsjsp-examples
JSP example URL = http://localhost/jsp-examples/

Servlets example Root = .xampptomcatwebappsservlets-examples
Servlets example URL = http://localhost/servlets-examples/

Mod_jk java Root = .xampptomcatweppappsjava
Mod_jk java URL = http://localhost/java/

倘若你想建立更多的映射,那么就需要自行修改.xamppapacheconfworkers2.properties文件

[@more@]

Categories
common

单子模式(SINGLETON)的简单实现

参考了超链接地址DevNet超链接地址Chinaunix.net 的讨论,用以下代码简单实现单子模式(SINGLETON):

代码片段:


<?php 
/**
*  Class: SingletonPool
*  Store multiple singletons (of different classes, naturally).
*
*/
class Singleton {

    
/**
    * 返回唯一对象,可保存多个对象
    *
    * @param (string) $class - the class name
    * @return object
    * @access public
    * @static
    */
    
function &getInstance($class) {
        static
$ob = array();

        if( !isset(
$ob[$class]) ) {
            
$ob[$class] = & new $class;
        }

        return
$ob[$class];
    }

}
?>
Categories
common

Apache的AddDefaultCharset

看了这篇文章:超链接地址配置 Apache 强行指定浏览器编码选择 ,俺也有些感想:

apache 2的配置文件中,AddDefaultCharset缺省是ISO-8859-1,所以很多人刚开始用的时候会把它改成GB2312,这样就可以避免乱码问题.

我也推荐人家用这个解决办法在一段时间里,直到有一次看到一个UTF-8编码的页面,始终是乱码,无可救药的乱码,任你如何调整浏览器的设置.无奈之下我把AddDefaultCharset那行整个屏蔽了,突然发现所有UTF-8页面恢复了正常,真的好神奇耶!!

从此,我深深的认识到:在AddDefaultCharset被屏蔽的情况下,页面的编码是由<meta>标记决定的.

Categories
common

新闻组上看到的mysql cluster安装过程

如下:

 I have recently had success setting up a MySQL Cluster, so I
thought I’d share what I did with everyone since it was such a challenge
for me to do and the documentation for how to set it up is so poor.
 

[@more@] 

######################### My Setup ####################################

Here is my setup:

I have two machines, Machine A and Machine B, that have requests and
updates to the db balanced by a router.  There is one IP address that
clients use to access the db.  The router distributes 50% of the
requests to Machine A and the remaining 50% to Machine B.  Therefore,
the db on both Machine A and Machine B must be exactly the same at all
times.  To achieve this I used MySQL Cluster.

 

I am running Redhat Linux 9 on both machines, and the machines are
physically identical.

 

Machine A ip = 10.0.2.39

Machine B ip = 10.0.2.38

########################### Installing ################################ 

I did the following on both machines:

 

- I installed MySql-Max (Linux (x86, glibc-2.2, static, gcc) 4.1.7 

http://dev.mysql.com/get/Downloads/MySQL-4.1/mysql-max-4.1.7-pc-linux-i6
86.tar.gz/from/pick

 

- I extracted the tar file into the root folder, and installed the mysql
db by running the mysql_install_db script in the scripts directory.  (In
the mysql directory type-  ./scripts/mysql_install_db)

 

- I then created a config.ini file which I placed in the mysql
directory.  I also created a my.cnf file which I placed in the
mysql/data directory.

################### Config.ini #######################################

 [NDBD DEFAULT]

NoOfReplicas= 2

 

[MYSQLD DEFAULT]

[NDB_MGMD DEFAULT]

[TCP DEFAULT]

 

[NDB_MGMD]

HostName= 10.0.2.39      (10.0.2.38 on machine B)

 

[NDBD]

HostName= 10.0.2.38

DataDir= /root/mysql/data

 

[NDBD]

HostName= 10.0.2.39

DataDir= /root/mysql/data

 

[MYSQLD]

[MYSQLD]

[MYSQLD]

###################### My.cnf ########################## 

The my.cnf file on both machines is:

[mysqld]

ndbcluster

###################### Starting the cluster ############# 

To start the cluster I did the following:

(please note that MySQL is installed in the /root/mysql directory)

 

Machine A:

- opened a terminal.

- typed-   cd mysql

- typed-   ./bin/ndb_mgmd

       - starts the cluster manager

- typed-   ./bin/ndbd --initial

       - please note, only use the '--initial' parameter if it is the

        first time you are starting the node.  

- typed- ./bin/mysqld_safe --user=root &

       - starts mysql.  The terminal may stick here so use ctrl-c to get

         a new prompt.

- typed- ./bin/mysql

       - starts the mysql monitor.

- typed-  use test;

       - to use the test database.

 

Machine B:

- follow the same steps as Machine A:

###################### Testing the cluster ############# 

On Machine A:

- at the mysql monitor prompt

- type-  use test;

      - to use the test database.

- type-  create table cluster_test (i int) engine=ndbcluster;

      - this should create a clustered table called cluster_test.

 

On Machine B:

- at the mysql monitor prompt

- type-  use test;

- type-  show tables;

      -  this should show the cluster_test table created on Machine A.

 

Inserting

Subsequent inserts etc. can be done at the mysql monitor prompt.

Example:

On Machine A:

-        type- insert into cluster_test values(314159);

 

On Machine B:

-        type- select * from cluster_test;

    - should display the value 314159.

##########################################################
Categories
common

在apache上给一个虚拟主机同时绑定两个端口

今天给同一虚拟主机添加了两个端口,过程如下:[@more@]

今天给同一虚拟主机添加了两个端口,过程如下:

绑定端口为:80,8080

1.在httpd.conf中添加:

Listen 8080

2.复制原虚拟主机配置

 

以下是代码片段:

<VirtualHost *:80>

…..

</VirtualHost>

添加:

 

以下是代码片段:

<VirtualHost *:8080>

…..

</VirtualHost>

但是实际上有更简化的写法:

以下是代码片段:

<VirtualHost *:80 *:8080>

…..

</VirtualHost>

 

重启apache观察配置是否生效

Categories
common

定制apache目录列表的描述

Apache中目录的Option设置为Indexes后,文件和文件夹将列表出来,其中有一项是‘描述’
Description的,这个属性可以对文件进行一些描述,但是如何赋值呢?