Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Saturday, June 26, 2010

PHP的几种运行方式及性能比较(资料整理)

更多精彩请到 http://www.139ya.com


  对于Web服务器是如何解析PHP页面的问题,以前只知道应该是有个PHP解释器,至于具体的运行方式倒是没有好好地去研究(不求甚解的表现,大大的 缺点),下面把这方面查到的资料整理记录一下。 Windows下配置PHP

  在Windows IIS 6.0下配置PHP,通常有CGI、ISAPI和FastCGI三种配置方式,这三种模式都可以在IIS 6.0下成功运行,下面我就讲一下这三种方式配置的区别和性能上的差异。

  1、CGI(通用网关接口/Common Gateway Interface)一般是可执行程序,例如EXE文件,和WEB服务器各自占据着不同的进程,而且一般一个CGI程序只能处理一个用户请求。这样,当用 户请求数量非常多时,会大量占用系统的资源,如内存、CPU时间等,造成效能低下。

  2、ISAPI(Internet Server Application Program Interface)是微软提供的一套面向WEB服务的API接口,它能实现CGI提供的全部功能,并在此基础上进行了扩展,如提供了过滤器应用程序接 口。ISAPI应用大多数以DLL动态库的形式使用,可以在被用户请求后执行,,在处理完一个用户请求后不会马上消失,而是继续驻留在内存中等待处理别的 用户输入。此外,ISAPI的DLL应用程序和WEB服务器处于同一个进程中,效率要显著高于CGI。

  在Windows Server 2003的IIS6下配置ISAPI方式的PHP,配置方法是,在IIS的“WEB服务扩展”中,添加一个新的WEB服务扩展,程序后缀为 PHP,ISAPI程序为php5isapi.dll,然后再“环境变量”-“系统变量”中增加变量名PHPRC,数值为php.ini的路径,在 Internet信息服务管理器中,选择网站或应用程序的根目录,打开目录属性页(右键选择“属性”),再选择“主目录”。点击“配置”按钮,选择“映 射”Tab页。点击“添加...”,在“可执行文件”设为:c:phpphp5isapi.dll,扩展名设为.php,选择“确认文件是否存在”,然后 “确定”保存设置。重启服务器即可完成PHP的配置。

  3、FastCGI是可伸缩架构的CGI开放扩展,其主要行为是将CGI解释 器进程保持在内存中并因此获得较高的性能。传统的CGI解释器的反复加载是CGI性能低下的主要原因,如果CGI解释器保持在内存中并接受FastCGI 进程管理器调度,则可以提供良好的性能、伸缩性等。

  FastCGI已经集成于IIS7,也支持IIS6,在IIS6中的安装方法可 参见微软的官方文档,我这里简单翻译一下。

  先点这里下载一个32位的FastCGI extension for IIS,然后将其安装,安装后的文件应该放到system32inetsrv目录下。之后打开system32inetsrv目录,执行下面的语句,其中 c:php为你的PHP目录,可以修改为其他数值。

  cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"c:phpphp-cgi.exe"

  在 Internet信息服务管理器中,选择网站或应用程序的根目录,打开目录属性页(右键选择“属性”),再选择“主目录”。点击“配置”按钮,选择“映 射”Tab页。点击“添加...”,在“可执行文件”设为: c:windowssystem32inetsrvfcgiext.dll,扩展名设为.php,选择“确认文件是否存在”,然后“确定”保存设置。

   修改php.ini文件,增加如下语句:

  fastcgi.impersonate = 1

   cgi.fix_pathinfo = 1

  cgi.force_redirect = 0

  之后打开 system32inetsrv目录,执行以下语句:

  cscript fcgiconfig.js -set -section:"PHP" -InstanceMaxRequests:10000

  cscript fcgiconfig.js -set -section:"PHP" -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000

  最后,配置c:php目录的安全性, 使得IIS_WPG组对于这个目录有读取和执行的权限。这时候,基于FastCGI的PHP就成功配置到IIS6上了。不过根据我自己的测 试,FastCGI的性能比ISAPI的好像高不了多少,不知道Windows Server2008下的IIS7是不是会好一些。这里是微软提供的基于内置FastCGI的IIS7安装PHP的方法。 Linux下配置PHP

   Linux下支持以FastCGI和mod_php的方式运行PHP。许多人采用mod_php,因为这是几乎所有Linux发行版的缺省方式。这种情 况下,PHP作为Apache的一个模块运行,因此PHP应用程序以Apache的权限运行,所以Drupal程序文件必须对Apache可读。

   下面是Apache对一个php页面请求的处理过程:

  从浏览器中点击一个链接。发送对yourserver/test.php的 请求。

  Apache得到对test.php的请求,它知道.php文件应由PHP预处理器(mod_php)处理,因此它通知 PHP处理它。它知道这些,是因为我们在Apache的配置中指定它。

  test.php是包含命令的一个PHP脚本。这些命令之一 是打开一个到一个数据库的连接并抓取数据。PHP 处理到数据库的连接,并且解释SQL调用从DB中提取数据。

  服务器服务器得到从 PHP解释器来的连接请求,并且处理这个请求。请求可能是类似于一个简单的选择语句,或数据库表创建等。

  数据库然后将应答和结果回 送到PHP解释器。

  Apache回送该结果到浏览器,作为对他请求的应答,现在看见的是一个包含从一个数据库来的一些信息的网页。

Monday, September 28, 2009

遭遇了"Call to undefined function socket_create()"

更多精彩请到 http://www.139ya.com

今天在试验php socket时,在c:\window\system32\cmd.exe里遭遇了Fatal error: Call to undefined function socket_create()。

google一下,发现跟我有同样问题的人还不少。一般的解决方案是:

1. 找到php.ini,看 extension=php_gd2.dll 和 extension=php_sockets.dll 扩展是否打开;

2. 看phpInfo()显示的内容里,socket模块是否为enable;



我检查了一下,发现都是符合的。但错误仍然出现?怎么回事呢?



后来我才发现,原来是我在phpInfo()里看到的和在cmd窗口里使用的php不是同一个东西。



原因是我多次安装过php. 先前的php在系统的环境变量里面注册了path。所以在cmd窗口里使用的是以前的php. 而在phpInfo()里显示的是现在的php的设置。



解决的办法很简单了,就把系统环境变量里的path里,指向老的Php的路径改为指向正在使用的Php的路径。这样在cmd里的php和在浏览器里的php就是同一个东西了。

Monday, July 6, 2009

Top Ten Open Source PHP Apps

更多精彩请到 http://www.139ya.com

http://www.moon-blog.com/2009/07/top-ten-open-source-php-apps.html

Top Ten Open Source PHP Apps

Filed Under development | 55

Open-source PHP applications that changed the world. From managing databases to shopping, writing blogs to sending emails. Ten years of passion, great software architectures, team work and revolutionary ideas. Here are the most influential open-source PHP applications.

Blog

Wordpress - is a state-of-the-art semantic personal publishing platform with a focus on aesthetics, web standards, and usability.

BBS

phpBB -is a high powered, fully scalable, and highly customizable open-source bulletin board package. phpBB has a user-friendly interface, simple and straightforward administration panel, and helpful FAQ. Based on the powerful PHP server language and your choice of MySQL, MS-SQL, PostgreSQL or Access/ODBC database servers, phpBB is the ideal free community solution for all web sites. Features include: Unlimited forums and posts; Multiple language interface; Private or public forums; Powerful search utility; Private messaging system; Templates.

CMS

Drupal - an open source content management platform. Equipped with a powerful blend of features, Drupal supports a variety of websites ranging from personal weblogs to large community-driven websites.

Wikis

MediaWiki - is a free software wiki package originally written for Wikipedia. It allows collaborative editing on documents within a familiar interface. It was designed to be run on a large server farm and requires Apache, PHP, and MySQL.

Database Tools

phpMyAdmin - handles the administration of MySQL over the Web. phpMyAdmin performs many database administration tasks like running SQL statements, adding and dropping databases, and adding, editing or deleting tables or fields.

Photo Tools

Gallery - is an open source project with the goal to develop and support leading photo sharing web application solutions. It allow some basic photo manipulation, such as resizing, rotating, and altering image quality, but does not include advanced photo editing.

Advertising Tools

OpenX - OpenX is a hugely popular, free ad server for web publishers. Take control, manage your advertising and make more money from online advertising today.

DIGG

Pligg - Pligg CMS provides free software to create your own social networking website. Start a site in minutes using Pligg Content Management System and save time and money on your next website.

RSS

Gregarius–Gregarius is a web-based RSS/RDF/ATOM feed aggregator, designed to run on your web server, allowing you to access your news sources from wherever you want.

E-Commerce

osCommerce - osCommerce(”open source Commerce”) is an e-commerce and online store-management software program. It can be used on any web server that has PHP and MySQL installed. osCommerce provides a basic set of functionality that meets the common needs of online businesses.

Thursday, April 16, 2009

PHP5+APACHE2.2配置成功案例(WindowsXP)

更多精彩请到 http://www.139ya.com


PHP5+APACHE2.2配置成功案例:

第一、安装并配置APACHE(以我的为例,安装到D:\servers\apache)

apache相关命令: D:\servers\apache\bin

httpd -k install : 注册apache httpd为windows 系统服务 (注意在系统服务中将其设为手动)

httpd -k start : 启动apache
httpd -k restart : 重启动apache

1、安装时默认安装,Network Domain, Server Name 我填写我的计算机名,Administrator's Email Address区域填你的邮件地址

2、安装完后在安装目录下有个conf文件夹,打开httpd.conf文件进行配置
·找到 DocumentRoot ,将其设置为你所要存放php, htm等网页文件的文件夹,如 "D:\servers\apache\htdocs";
·找到 Directory,将其设置为你所要存放php, htm等网页文件的文件夹,如 "D:\servers\apache\htdocs";
·找到 DirectoryIndex ,在index.html后添加index.php, index.htm等,以单个空格将其分开;

·重启Apache (httpd -k restart),
用http://localhost或http://127.0.0.1或http://yourcompanyname测试是否成功。成功的话屏幕会有个It works! (当然在你新的

htdocs目录下要有index.html)

第二、安装配置PHP(解压PHP压缩包到d:\php\)
1、将php.ini-recommended文件重命名为php.ini并将其剪到系统所在目录下(如放在2000/NT的WINNT/system32, XP的Windows目录下!!!),
2、将extension_dir 改为php/ext所在目录,如 "d:\php\ext";
3、将doc_root 改为第一步中的同样目录,如 "E:\Program Files\Apache Software Foundation\Apache2.2\htdocs";
4、找到 ;session.save_path = "/tmp" ,将';'去掉,设置你保存session的目录,如session.save_path = "D:/php/session_temp"
5、将php 目录下的libmysql.dll, php_mysql.dll, php_mysqli.dll 拷到XP的Windows目录下!!!


5、然后把下面几句前面的分号去掉,以更好支持Mysql and PHPmyadmin
extension=php_mbstring.dll
extension=php_gd2.dll
extension=php_mysql.dll
第三、PHP+APACHE
1、允许Apache将PHP程序作为模块来运行:
打开httpd.conf,添加下面内容(位置任意):
LoadModule php5_module "d:/php/php5apache2_2.dll"(特别注意这一条,很多地方是调用php5apache2.dll,这样在运行

PHP代码时会提示httpd.exe应用程序错误)
AddType application/x-httpd-php .php
AddType application/x-httpd-php .htm
(.htm, .php为可执行php语言的扩展名,也可加html, php3, php4,甚至txt)

---------------------------------------------------------------------------------------------
(以下两步可以不需要!!!!!!)

2、如果你出于某种原因而需要在CGI模式中运行PHP程序(使用Php.exe),
请将上面这一行变成注释(各行头加#即可),添加下面这些行:
# ScriptAlias /php/ "d:/php/"
# AddType application/x-httpd-php .php
#Action application/x-httpd-php "/php/php-cgi.exe"
3、现在apache 2 支持HTML而不支持PHP,先把下面几句加到d:\apache2\conf\httpd.conf去:
# ScriptAlias /php/ "d:/php/"
# AddType application/x-httpd-php .php
#Action application/x-httpd-php "/php/php-cgi.exe"
---------------------------------------------------------------------------------------------

第四、重起服务 httpd -k restart
1、在d:\PHP里找到php5ts.dll,libmysql.dll将其复制到c:\winnt\system32下(winNT/2000的机器),而winXP/2003是复制到

c:\windows\system32下
2、测试Apache与php是否连接成功:
启动start apache服务或者正在运行的就重新启动restart apache
3、在Web根目录下新建test.php(即E:\Program Files\Apache Software Foundation\Apache2.2\htdocs目下)







4、运行http://localhost/test.php
如果成功,则应该看到一个含有PHP徽标的网页,其中包含大量设置和其他信息
那么恭喜你

Thursday, March 5, 2009

PHP5+APACHE2.2配置

更多精彩请到 http://www.139ya.com

PHP5+APACHE2.2配置:

第一、安装并配置APACHE(以我的为例,安装到D:\servers\apache)

apache相关命令: D:\servers\apache\bin

httpd -k install : 注册apache httpd为windows 系统服务 (注意在系统服务中将其设为手动)

httpd -k start : 启动apache
httpd -k restart : 重启动apache

1、安装时默认安装,Network Domain, Server Name 我填写我的计算机名,Administrator's Email Address区域填你的邮件地址

2、安装完后在安装目录下有个conf文件夹,打开httpd.conf文件进行配置
·找到 DocumentRoot ,将其设置为你所要存放php, htm等网页文件的文件夹,如 "D:\servers\apache\htdocs";
·找到 Directory,将其设置为你所要存放php, htm等网页文件的文件夹,如 "D:\servers\apache\htdocs";
·找到 DirectoryIndex ,在index.html后添加index.php, index.htm等,以单个空格将其分开;

·重启Apache (httpd -k restart),
用http://localhost或http://127.0.0.1或http://yourcompanyname测试是否成功。成功的话屏幕会有个It works! (当然在你新的

htdocs目录下要有index.html)

第二、安装配置PHP(解压PHP压缩包到d:\php\)
1、将php.ini-recommended文件重命名为php.ini并将其剪到系统所在目录下(如放在2000/NT的WINNT/system32, XP的

Windows目录下),
2、将extension_dir 改为php/ext所在目录,如 "d:\php\ext";
3、将doc_root 改为第一步中的同样目录,如 "E:\Program Files\Apache Software Foundation\Apache2.2\htdocs";
4、找到 ;session.save_path = "/tmp" ,将';'去掉,设置你保存session的目录,如session.save_path = "D:/php/session_temp"


5、然后把下面几句前面的分号去掉,以更好支持Mysql and PHPmyadmin
extension=php_mbstring.dll
extension=php_gd2.dll
extension=php_mysql.dll
extension=php_mysqli.dll
第三、PHP+APACHE
1、允许Apache将PHP程序作为模块来运行:
打开httpd.conf,添加下面内容(位置任意):
LoadModule php5_module "d:/php/php5apache2_2.dll"(特别注意这一条,很多地方是调用php5apache2.dll,这样在运行

PHP代码时会提示httpd.exe应用程序错误)
AddType application/x-httpd-php .php
AddType application/x-httpd-php .htm
(.htm, .php为可执行php语言的扩展名,也可加html, php3, php4,甚至txt)

---------------------------------------------------------------------------------------------
(以下两步可以不需要!!!!!!)

2、如果你出于某种原因而需要在CGI模式中运行PHP程序(使用Php.exe),
请将上面这一行变成注释(各行头加#即可),添加下面这些行:
# ScriptAlias /php/ "d:/php/"
# AddType application/x-httpd-php .php
#Action application/x-httpd-php "/php/php-cgi.exe"
3、现在apache 2 支持HTML而不支持PHP,先把下面几句加到d:\apache2\conf\httpd.conf去:
# ScriptAlias /php/ "d:/php/"
# AddType application/x-httpd-php .php
#Action application/x-httpd-php "/php/php-cgi.exe"
---------------------------------------------------------------------------------------------

第四、重起服务 httpd -k restart
1、在d:\PHP里找到php5ts.dll,libmysql.dll将其复制到c:\winnt\system32下(winNT/2000的机器),而winXP/2003是复制到

c:\windows\system32下
2、测试Apache与php是否连接成功:
启动start apache服务或者正在运行的就重新启动restart apache
3、在Web根目录下新建test.php(即E:\Program Files\Apache Software Foundation\Apache2.2\htdocs目下)


<html>
<head><title>test</title></head>
<body>
<?php
phpinfo();
?>
</body>
</html>


4、运行http://localhost/test.php
如果成功,则应该看到一个含有PHP徽标的网页,其中包含大量设置和其他信息
那么恭喜你