【来源】http://www.phpchina.com/?action-viewnews-itemid-38710

  在了解过世界最大的PHP站点,Facebook的后台技术后,今天我们来了解一个百万级PHP站点的网站架构:Poppen.de。Poppen.de是德国的一个社交网站,相对Facebook、Flickr来说是一个很小的网站,但它有一个很好的架构,融合了很多技术,如 Nigix、MySql、CouchDB、Erlang、Memcached、RabbitMQ、PHP、Graphite、Red5以及Tsung。

统计信息

◆200万注册用户数;

◆2万并发用户数;

◆每天20万条私有消息;

◆每天25万登录次数;

◆项目团队有11个开发人员,两个设计,两个系统管理员;

商业模式

该网站采用免费增值模式,用户可以免费使用下面任何服务:

◆搜索其他用户;

◆给好友发送消息;

◆上载图片和视频;

◆寻找好友;

◆视频聊天;

◆更多…

但如果用户想享受不受限制发送消息和上载图片,那么就得根据需要支付不同类型的会员服务,视频聊天及网站其他服务也采用同样的策略。

工具箱

Nginx

Poppen.de 所有的服务都是基于Nginx服务上的。前端有两台Nginx服务器在高峰期提供每分钟15万次请求的负载,每个机器已经有四年寿命,并且只有一个CPU 和3GB RAM。Poppen.de拥有三台独立的图像服务器,由三台Nginx服务器为*.bilder.poppen.de提供每分钟8万次请求服务。

Nginx 架构中一个很酷的设计就是有很多请求是由Memcached处理的,因此请求从缓存中获取内容而不需要直接访问PHP机器。比如,用户信息页(user profile)是网站需要密集处理的内容,如果把用户信息页全部缓存到Memcached上,那么请求直接从Memcached上获取内容。 Poppen.de的Memcached每分钟可以处理8000次请求。

架构中有三个Nginx图像服务器提供本地图像缓存,用户上载图 像到一个中央文件服务器。当向这三个Nginx之一中请求图像时,如果服务器本地中没有存在该图像,则从中央文件服务器下载到该服务器上作缓存并提供服 务。这种负载均衡的分布式图像服务器架构设计可以减轻主要存储设备的负载。

PHP-FPM

该网站运行在PHP- FPM上。共有28台双CPU、6GB内存的PHP机器,每个机器上运行100个PHP-FPM的工作线程。使用启用了APC的PHP5.3.x。 PHP5.3可以降低CPU和内存使用率的30%以上。

程序代码是基于Symfony1.2框架之上开发的。一是可以使用外部资源,二是 能够提高项目开发进度,同时在一个著名的框架上可以让新开发人员更容易加入到团队中来。虽然没有任何事情都是十全十美的,但可以从Symfony框架中得 到很多好处,让团队可以更多的精力放在Poppen.de的业务开发上去。

网站性能优化使用XHProf,这是Facebook开源出来的一个类库。这个框架非常容易个性化和配置,能够可以缓存大部分高代价的服务器计算。

MySQL

MySQL是网站 主要的RDBMS。网站又几个MySql服务器:一台4CPU、32GB的服务器存储用户相关信息,如基本信息、照片描述信息等。这台机器已经使用了4 年,下一步计划会使用共享集群来替换它。目前仍基于这个系统上进行设计,以简化数据访问代码。根据用户ID进行数据分区,因为网站中大部分信息都是以用户 为中心的,如照片、视频、消息等。

有三台服务器按主-从-从配置架构提供用户论坛服务。一台从服务器负责网站自定义消息存储,到现在有 2.5亿条消息。另外四台机器为主-从配置关系。另外由4台机器配置成NDB族群专门服务于密集型写操作数据,如用户访问统计信息。

数据表设计尽量避免关联操作,尽可能缓存最多的数据。当然,数据库的结构化规范已经完全被破坏掉了。因此,为了更容易搜索,数据库设计创建了数据挖掘表。大部分表是MyISAM型表,可以提供快速查找。现在的问题是越来越多的表已经全表锁住了。Poppen.de正考虑往XtraDB存储引擎上迁移。

Memcached

网站架构中Memcached应用相当多,超过45GB的高速缓存和51个节点。缓存了Session会话、视图缓存以及函数执行缓存等。架构中有一个系统 当记录被修改时可以自动地把数据更新到缓存中去。未来改善缓存更新的可能方案是使用新的Redis Hash API或者MongoDB。

RabbitMQ

在 2009年中开始在架构中使用RabbitMQ。这是一个很好的消息解决方案,便于部署和集中到这个架构中去,在LVS后运行了两台RabbitMQ服务 器。在上个月,已经把更多的东西集成到该队列中,意味着同一时刻有28台PHP服务器每天要处理50万次请求。发送日志、邮件通知、系统消息、图像上载等 更多的东西到这个队列中。

应用PHP-FPM中的fastcgi_finish_request()函数集成队列消息,可以把消息异步发 送到队列中。当系统需要给用户发送HTML或JSON格式响应时,就调用这个函数,这样用户就没有必要等到PHP脚本清理。

这个系统可以改善架构资源管理。例如,在高峰期服务每分钟可以处理1000次登录请求。这表示有1000并发更新用户表保存用户的登录时间。由于使用了队列机制,可以 按相反的顺序来运行这些查询。如果需要提高处理速度,只需要增加更多的队列处理者即可,甚至可以增加更多的服务器到这集群中去,而不需要修改任何配置和部 署新节点。

CouchDB

日志存储CouchDB运行在一台机器上。在这台机器上可以根据模块/行为进行日志查询 /分组,或者根据错误类型等等。这对定位问题非常有用。在使用日志聚合服务CouchDB之前,不得不逐台登录到PHP服务器上设法日志分析定位问题,这 是非常麻烦的。而现在把所有的日志集中到队列中保存到CouchDB中,可以集中进行问题检查和分析。

Graphite

网站使用Graphite采集网站实时信息并统计。从请求每个模块/行为到Memcached的命中和未命中、RabbitMQ状态监控以及Unix负载等等。Graphite服务平均每分钟有4800次更新操作。实践已经证实要监测网站发发生什么是非常有用的,它的简单文本协议和绘图功能可以方便地即插即 用的方式用于任何需要监控的系统上。

一件很酷的事情是使用Graphite同时监控了网站的两个版本。一月份部署了Symfony框架新 版本,以前代码作为一个备份部署。这就意味着网站可能会面临性能问题。因此可以使用Graphite来对两个版本在线进行对比。

发现新版本上的Unix负载表较高,于是使用XHProf对两个版本进行性能分析,找出问题所在。

Red5

网站为用户也提供了两种类型的视频服务,一种是用户自己上载的视频,另外一种是视频聊天,用户视频互动和分享。到2009年年中,每月为用户提供17TB的流量服务。

Tsung

Tsung 是一个Erlang编写的分布式基准分析工具。在Poppen.de网站中主要用于HTTP基准分析、MySQL与其他存储系统(XtraDB)的对比分 析。用一个系统记录了主要的MySQL服务器的流量,再转换成Tsung的基准会话。然后对该流量进行回放,由Tsung产生数以千计的并发用户访问实验 室的服务器。这样就可以在实验环境中与真实场景非常接近。

SELECT g.goods_id,g.cat_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, IFNULL(mp.user_price, g.shop_price * '1') AS shop_price, g.promote_price, g.goods_type, g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img FROM `u114287a`.`ecs_goods` AS g LEFT JOIN `u114287a`.`ecs_member_price` AS mp ON mp.goods_id = g.goods_id AND mp.user_rank = '0' WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND (g.cat_id IN ('8') OR g.goods_id IN ('14','17','31') ) ORDER BY (case when g.cat_id=8 then 1 when g.cat_id IN ('8') then 2 else 3 end),goods_id DESC

ORDER BY (case when g.cat_id=8 then 1 when g.cat_id IN (’8′) then 2 else 3 end)

满足第一个条件排前面,接着满足第二个条件排第二,剩下排第三

.replace(/<img(.*?)src=\”(.*?)\”(.*?)>/i,”);

在include/lib_insert.php

增加一个insert函数,是叠加变量通过这个insert组合起来
function insert_adsCat($arr)
{
return $arr['cats_config']['cat_list'][$arr['id']][$arr['need']];
}

在模板调用

{insert name=’adsCat’ id=$rec_data['cat_id'] cats_config=$cats_config need=’url’}

把你需要组合的数组里面字段通过参数形式传给lib_insert.php组合

下载地址

http://www.yiiframework.com/extension/upload

文档

http://www.verot.net/php_class_upload_docs.htm

class.upload.php documentation

Description
Description | Vars (details) | Methods (details)

What does it do?

It manages file uploads for you. In short, it manages the uploaded file, and allows you to do whatever you want with the file, especially if it is an image, and as many times as you want.

It is the ideal class to quickly integrate file upload in your site. If the file is an image, you can convert, resize, crop it in many ways. You can also apply filters, add borders, text, watermarks, etc… That’s all you need for a gallery script for instance. Supported formats are PNG, JPG, GIF and BMP.

You can also use the class to work on local files, which is especially useful to use the image manipulation features. The class also supports Flash uploaders.

The class works with PHP 4 and 5, and its error messages can be localized at will.

How does it work?

You instanciate the class with the $_FILES['my_field'] array where my_field is the field name from your upload form. The class will check if the original file has been uploaded to its temporary location (alternatively, you can instanciate the class with a local filename).

You can then set a number of processing variables to act on the file. For instance, you can rename the file, and if it is an image, convert and resize it in many ways. You can also set what will the class do if the file already exists.

Then you call the function process to actually perform the actions according to the processing parameters you set above. It will create new instances of the original file, so the original file remains the same between each process. The file will be manipulated, and copied to the given location. The processing variables will be reset once it is done.

You can repeat setting up a new set of processing variables, and calling process again as many times as you want. When you have finished, you can call clean to delete the original uploaded file.

If you don’t set any processing parameters and call process just after instanciating the class. The uploaded file will be simply copied to the given location without any alteration or checks.

Don’t forget to add enctype=”multipart/form-data” in your form tag <form> if you want your form to upload the file.

How to use it?
Create a simple HTML file, with a form such as:

 <form enctype="multipart/form-data" method="post" action="#">
   <input type="file" size="32" name="image_field" value="">
   <input type="submit" name="Submit" value="upload">
 </form>

Create a file called upload.php:

  $handle = new upload($_FILES['image_field']);
  if ($handle->uploaded) {
      $handle->file_new_name_body   = 'image_resized';
      $handle->image_resize         = true;
      $handle->image_x              = 100;
      $handle->image_ratio_y        = true;
      $handle->process('/home/user/files/');
      if ($handle->processed) {
          echo 'image resized';
          $handle->clean();
      } else {
          echo 'error : ' . $handle->error;
      }
  }

How to process local files?
Use the class as following, the rest being the same as above:

  $handle = new upload('/home/user/myfile.jpg');

How to set the language?
Instantiate the class with a second argument being the language code:

  $handle = new upload($_FILES['image_field'], 'fr_FR');
  $handle = new upload('/home/user/myfile.jpg', 'fr_FR');

How to output the resulting file or picture directly to the browser?
Simply call process() without an argument (or with null as first argument):

  $handle = new upload($_FILES['image_field']);
  header('Content-type: ' . $handle->file_src_mime);
  echo $handle->Process();
  die();

Or if you want to force the download of the file:

  $handle = new upload($_FILES['image_field']);
  header('Content-type: ' . $handle->file_src_mime);
  header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";");
  echo $handle->Process();
  die();

Processing parameters (reset after each process)

  • file_new_name_body replaces the name body (default: ”)
    $handle->file_new_name_body = 'new name';
  • file_name_body_add appends to the name body (default: ”)
    $handle->file_name_body_add = '_uploaded';
  • file_name_body_pre prepends to the name body (default: ”)
    $handle->file_name_body_pre = 'thumb_';
  • file_new_name_ext replaces the file extension (default: ”)
    $handle->file_new_name_ext = 'txt';
  • file_safe_name formats the filename (spaces changed to _) (default: true)
    $handle->file_safe_name = true;
  • file_overwrite sets behaviour if file already exists (default: false)
    $handle->file_overwrite = true;
  • file_auto_rename automatically renames file if it already exists (default: true)
    $handle->file_auto_rename = true;
  • dir_auto_create automatically creates destination directory if missing (default: true)
    $handle->auto_create_dir = true;
  • dir_auto_chmod automatically attempts to chmod the destination directory if not writeable (default: true)
    $handle->dir_auto_chmod = true;
  • dir_chmod chmod used when creating directory or if directory not writeable (default: 0777)
    $handle->dir_chmod = 0777;
  • file_max_size sets maximum upload size (default: upload_max_filesize from php.ini)
    $handle->file_max_size = '1024'; // 1KB
  • mime_check sets if the class check the MIME against the allowed list (default: true)
    $handle->mime_check = true;
  • no_script sets if the class turns scripts into text files (default: true)
    $handle->no_script = false;
  • allowed array of allowed mime-types. wildcard accepted, as in image/* (default: check Init)
    $handle->allowed = array('application/pdf','application/msword', 'image/*');
  • forbidden array of forbidden mime-types. wildcard accepted, as in image/* (default: check Init)
    $handle->forbidden = array('application/*');
  • image_convert if set, image will be converted (possible values : ”|’png’|'jpeg’|'gif’|'bmp’; default: ”)
    $handle->image_convert = 'jpg';
  • image_background_color if set, will forcibly fill transparent areas with the color, in hexadecimal (default: null)
    $handle->image_background_color = '#FF00FF';
  • image_default_color fallback color background color for non alpha-transparent output formats, such as JPEG or BMP, in hexadecimal (default: #FFFFFF)
    $handle->image_default_color = '#FF00FF';
  • jpeg_quality sets the compression quality for JPEG images (default: 85)
    $handle->jpeg_quality = 50;
  • jpeg_size if set to a size in bytes, will approximate jpeg_quality so the output image fits within the size (default: null)
    $handle->jpeg_size = 3072;

The following eight settings can be used to invalidate an upload if the file is an image (note that open_basedirrestrictions prevent the use of these settings)

  • image_max_width if set to a dimension in pixels, the upload will be invalid if the image width is greater (default: null)
    $handle->image_max_width = 200;
  • image_max_height if set to a dimension in pixels, the upload will be invalid if the image height is greater (default: null)
    $handle->image_max_height = 100;
  • image_max_pixels if set to a number of pixels, the upload will be invalid if the image number of pixels is greater (default: null)
    $handle->image_max_pixels = 50000;
  • image_max_ratio if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is greater (default: null)
    $handle->image_max_ratio = 1.5;
  • image_min_width if set to a dimension in pixels, the upload will be invalid if the image width is lower (default: null)
    $handle->image_min_width = 100;
  • image_min_height if set to a dimension in pixels, the upload will be invalid if the image height is lower (default: null)
    $handle->image_min_height = 500;
  • image_min_pixels if set to a number of pixels, the upload will be invalid if the image number of pixels is lower (default: null)
    $handle->image_min_pixels = 20000;
  • image_min_ratio if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is lower (default: null)
    $handle->image_min_ratio = 0.5;
  • image_resize determines is an image will be resized (default: false)
    $handle->image_resize = true;

The following variables are used only if image_resize == true

  • image_x destination image width (default: 150)
    $handle->image_x = 100;
  • image_y destination image height (default: 150)
    $handle->image_y = 200;

Use either one of the following

  • image_ratio if true, resize image conserving the original sizes ratio, using image_x AND image_y as max sizes if true (default: false)
    $handle->image_ratio = true;
  • image_ratio_crop if true, resize image conserving the original sizes ratio, using image_x AND image_y as max sizes, and cropping excedent to fill the space. setting can also be a string, with one or more from ‘TBLR’, indicating which side of the image will be kept while cropping (default: false)
    $handle->image_ratio_crop = true;
  • image_ratio_fill if true, resize image conserving the original sizes ratio, using image_x AND image_y as max sizes, fitting the image in the space and coloring the remaining space. setting can also be a string, with one or more from ‘TBLR’, indicating which side of the space the image will be in (default: false)
    $handle->image_ratio_fill = true;
  • image_ratio_no_zoom_in same as image_ratio, but won’t resize if the source image is smaller thanimage_ximage_y (default: false)
    $handle->image_ratio_no_zoom_in = true;
  • image_ratio_no_zoom_out same as image_ratio, but won’t resize if the source image is bigger thanimage_ximage_y (default: false)
    $handle->image_ratio_no_zoom_out = true;
  • image_ratio_x if true, resize image, calculating image_x from image_y and conserving the original sizes ratio (default: false)
    $handle->image_ratio_x = true;
  • image_ratio_y if true, resize image, calculating image_y from image_x and conserving the original sizes ratio (default: false)
    $handle->image_ratio_y = true;
  • image_ratio_pixels if set to a long integer, resize image, calculating image_y and image_x to match a the number of pixels (default: false)
    $handle->image_ratio_pixels = 25000;

The following image manipulations require GD2+

  • image_brightness if set, corrects the brightness. value between -127 and 127 (default: null)
    $handle->image_brightness = 40;
  • image_contrast if set, corrects the contrast. value between -127 and 127 (default: null)
    $handle->image_contrast = 50;
  • image_tint_color if set, will tint the image with a color, value as hexadecimal #FFFFFF (default: null)
    $handle->image_tint_color = '#FF0000';
  • image_overlay_color if set, will add a colored overlay, value as hexadecimal #FFFFFF (default: null)
    $handle->image_overlay_color = '#FF0000';
  • image_overlay_percent used when image_overlay_color is set, determines the opacity (default: 50)
    $handle->image_overlay_percent = 20;
  • image_negative inverts the colors in the image (default: false)
    $handle->image_negative = true;
  • image_greyscale transforms an image into greyscale (default: false)
    $handle->image_greyscale = true;
  • image_threshold applies a threshold filter. value between -127 and 127 (default: null)
    $handle->image_threshold = 20;
  • image_unsharp applies an unsharp mask, with alpha transparency support (default: false)
    $handle->image_unsharp = true;
  • image_unsharp_amount unsharp mask amount, typically 50 – 200 (default: 80)
    $handle->image_unsharp_amount = 120;
  • image_unsharp_radius unsharp mask radius, typically 0.5 – 1 (default: 0.5)
    $handle->image_unsharp_radius = 0.8;
  • image_unsharp_threshold unsharp mask threshold, typically 0 – 5 (default: 1)
    $handle->image_unsharp_threshold = 0;
  • image_text creates a text label on the image, value is a string, with eventual replacement tokens (default: null)
    $handle->image_text = 'test';
  • image_text_direction text label direction, either ‘h’ horizontal or ‘v’ vertical (default: ‘h’)
    $handle->image_text_direction = 'v';
  • image_text_color text color for the text label, in hexadecimal (default: #FFFFFF)
    $handle->image_text_color = '#FF0000';
  • image_text_percent text opacity on the text label, integer between 0 and 100 (default: 100)
    $handle->image_text_percent = 50;
  • image_text_background text label background color, in hexadecimal (default: null)
    $handle->image_text_background = '#FFFFFF';
  • image_text_background_percent text label background opacity, integer between 0 and 100 (default: 100)
    $handle->image_text_background_percent = 50;
  • image_text_font built-in font for the text label, from 1 to 5. 1 is the smallest (default: 5)
    $handle->image_text_font = 4;
  • image_text_x absolute text label position, in pixels from the left border. can be negative (default: null)
    $handle->image_text_x = 5;
  • image_text_y absolute text label position, in pixels from the top border. can be negative (default: null)
    $handle->image_text_y = 5;
  • image_text_position text label position withing the image, a combination of one or two from ‘TBLR’: top, bottom, left, right (default: null)
    $handle->image_text_position = 'LR';
  • image_text_padding text label padding, in pixels. can be overridden by image_text_padding_x andimage_text_padding_y (default: 0)
    $handle->image_text_padding = 5;
  • image_text_padding_x text label horizontal padding (default: null)
    $handle->image_text_padding_x = 2;
  • image_text_padding_y text label vertical padding (default: null)
    $handle->image_text_padding_y = 10;
  • image_text_alignment text alignment when text has multiple lines, either ‘L’, ‘C’ or ‘R’ (default: ‘C’)
    $handle->image_text_alignment = 'R';
  • image_text_line_spacing space between lines in pixels, when text has multiple lines (default: 0)
    $handle->image_text_line_spacing = 3;
  • image_flip flips image, wither ‘h’ horizontal or ‘v’ vertical (default: null)
    $handle->image_flip = 'h';
  • image_rotate rotates image. possible values are 90, 180 and 270 (default: null)
    $handle->image_rotate = 90;
  • image_crop crops image. accepts 4, 2 or 1 values as ‘T R B L’ or ‘TB LR’ or ‘TBLR’. dimension can be 20, or 20px or 20% (default: null)
    $handle->image_crop = array(50,40,30,20); OR '-20 20%'...
  • image_precrop crops image, before an eventual resizing. accepts 4, 2 or 1 values as ‘T R B L’ or ‘TB LR’ or ‘TBLR’. dimension can be 20, or 20px or 20% (default: null)
    $handle->image_precrop = array(50,40,30,20); OR '-20 20%'...
  • image_bevel adds a bevel border to the image. value is thickness in pixels (default: null)
    $handle->image_bevel = 20;
  • image_bevel_color1 top and left bevel color, in hexadecimal (default: #FFFFFF)
    $handle->image_bevel_color1 = '#FFFFFF';
  • image_bevel_color2 bottom and right bevel color, in hexadecimal (default: #000000)
    $handle->image_bevel_color2 = '#000000';
  • image_border adds a unicolor border to the image. accepts 4, 2 or 1 values as ‘T R B L’ or ‘TB LR’ or ‘TBLR’. dimension can be 20, or 20px or 20% (default: null)
    $handle->image_border = '3px'; OR '-20 20%' OR array(3,2)...
  • image_border_color border color, in hexadecimal (default: #FFFFFF)
    $handle->image_border_color = '#FFFFFF';
  • image_frame type of frame: 1=flat 2=crossed (default: null)
    $handle->image_frame = 2;
  • image_frame_colors list of hex colors, in an array or a space separated string (default: ‘#FFFFFF #999999 #666666 #000000′)
    $handle->image_frame_colors = array('#999999',  '#FF0000', '#666666', '#333333', '#000000');
  • image_watermark adds a watermark on the image, value is a local filename. accepted files are GIF, JPG, BMP, PNG and PNG alpha (default: null)
    $handle->image_watermark = 'watermark.png';
  • image_watermark_x absolute watermark position, in pixels from the left border. can be negative (default: null)
    $handle->image_watermark_x = 5;
  • image_watermark_y absolute watermark position, in pixels from the top border. can be negative (default: null)
    $handle->image_watermark_y = 5;
  • image_watermark_position watermark position withing the image, a combination of one or two from ‘TBLR’: top, bottom, left, right (default: null)
    $handle->image_watermark_position = 'LR';
  • image_watermark_no_zoom_in prevents the watermark to be resized up if it is smaller than the image (default: true)
    $handle->image_watermark_no_zoom_in = false;
  • image_watermark_no_zoom_out prevents the watermark to be resized down if it is bigger than the image (default: false)
    $handle->image_watermark_no_zoom_out = true;
  • image_reflection_height if set, a reflection will be added. Format is either in pixels or percentage, such as 40, ’40′, ’40px’ or ’40%’ (default: null)
    $handle->image_reflection_height = '25%';
  • image_reflection_space space in pixels between the source image and the reflection, can be negative (default: null)
    $handle->image_reflection_space = 3;
  • image_reflection_color reflection background color, in hexadecimal. Now deprecated in favor ofimage_default_color (default: #FFFFFF)
    $handle->image_default_color = '#000000';
  • image_reflection_opacity opacity level at which the reflection starts, integer between 0 and 100 (default: 60)
    $handle->image_reflection_opacity = 60;

Values that can be read before calling process()

If the file is a supported image type (and open_basedir restrictions allow it)

Values that can be read after calling process()

If the file is a supported image type

Requirements

Most of the image operations require GD. GD2 is greatly recommended

The class is compatible with PHP 4.3+, and compatible with PHP5

Changelog

  • v 0.30 05/09/2010
    - implemented an unsharp mask, with alpha transparency support, activated if image_unsharp is true. added image_unsharp_amountimage_unsharp_radius, and image_unsharp_threshold
    - added text/rtf MIME type, and no_script exception
    - corrected bug when no_script is activated and several process() are called
    - better error handling for finfo
    - display upload_max_filesize information from php.ini in the log
    - automatic extension for extension-less images
    - fixed image_ratio_fill top and left filling
    - fixed alphablending issue when applying a transparent PNG watermark on a transparent PNG
    - added image_watermark_no_zoom_in and image_watermark_no_zoom_out to allow the watermark to be resized down (or up) to fit in the image. By default, the watermark may be resized down, but not up.
  • v 0.29 03/02/2010
    - added protection against malicious images
    - added zip and torrent MIME type
    - replaced split() with explode()
    - initialise image_dst_x/y with image_src_x/y
    - removed mime_fileinfomime_filemime_magic and mime_getimagesize from the docs since they are used before process
    - added more extensions and MIME types
    - improved MIME type validation
    - improved logging
  • v 0.28 10/08/2009
    - replaced ereg functions to be compatible with PHP 5.3
    - added flv MIME type
    - improved MIME type detection
    - added file_name_body_pre to prepend a string to the file name
    - added mime_fileinfomime_filemime_magic and mime_getimagesize so that it is possible to deactivate some MIME type checking method
    - use exec() rather than shell_exec(), to play better with safe mode
    - added some error messages
    - fix bug when checking on conditions, processed wasn’t propagated properly
  • v 0.27 14/05/2009
    - look for the language files directory from __FILE__
    - deactivate file_auto_rename if file_overwrite is set
    - improved transparency replacement for true color images
    - fixed calls to newer version of UNIX file utility
    - fixed error when using PECL Fileinfo extension in SAFE MODE, and when using the finfo class
    - added image_precrop to crop the image before an eventual resizing
  • v 0.26 13/11/2008
    - rewrote conversion from palette to true color to handle transparency better
    - fixed imagecopymergealpha() when the overlayed image is of wrong dimensions
    - fixed imagecreatenew() when the image to create have less than 1 pixels width or height
    - rewrote MIME type detection to be more secure and not rely on browser information; now using Fileinfo PECL extension, UNIX file() command, MIME magic, and getimagesize(), in that order
    - added support for Flash uploaders
    - some bug fixing and error handling
  • v 0.25 17/11/2007
    - added translation files and mechanism to instantiate the class with a language different from English
    - added forbidden to set an array of forbidden MIME types
    - implemented support for simple wildcards in allowed and forbidden, such as image/*
    - preset the file extension to the desired conversion format when converting an image
    - added read and write support for BMP images
    - added a flag file_is_image to determine if the file is a supported image type
    - the class now provides some information about the image, before calling process(). Available areimage_src_ximage_src_y and the newly introduced image_src_bitsimage_src_pixels and image_src_type. Note that this will not work if open_basedir restrictions are in place
    - improved logging; now provides useful system information
    - added some more pre-processing checks for files that are images: image_max_widthimage_max_height,image_max_pixelsimage_max_ratioimage_min_widthimage_min_heightimage_min_pixels andimage_min_ratio
    - added image_ratio_pixels to resize an image to a number of pixels, keeping aspect ratio
    - added image_is_palette and image_is_transparent and image_transparent_color for GIF images
    - added image_default_color to define a fallback color for non alpha-transparent output formats, such as JPEG or BMP
    - changed image_background_color, which now forces transparent areas to be painted
    - improved reflections and color overlays so that it works with alpha transparent images
    image_reflection_color is now deprecated in favour of image_default_color
    - transparent PNGs are now processed in true color, and fully preserving the alpha channel when doing merges
    - transparent GIFs are now automatically detected. preserve_transparency is deprecated
    - transparent true color images can be saved as GIF while retaining transparency, semi transparent areas being merged with image_default_color
    - transparent true color images can be saved as JPG/BMP with the semi transparent areas being merged withimage_default_color
    - fixed conversion of images to true color
    - the class can now output the uploaded files content as the return value of process() if the function is called with an empty or null argumenti, or no argument
  • v 0.24 25/05/2007
    - added image_background_color, to set the default background color of an image
    - added possibility of using replacement tokens in text labels
    - changed default JPEG quality to 85
    - fixed a small bug when using greyscale filter and associated filters
    - added image_ratio_fill in order to fit an image within some dimensions and color the remaining space. Very similar to image_ratio_crop
    - improved the recursive creation of directories
    - the class now converts palette based images to true colors before doing graphic manipulations
  • v 0.23 23/12/2006
    - fixed a bug when processing more than once the same uploaded file. If there is an open_basedir restriction, the class now creates a temporary file for the first call to process(). This file will be used for subsequent processes, and will be deleted upon calling clean()
  • v 0.22 16/12/2006
    - added automatic creation of a temporary file if the upload directory is not within open_basedir
    - fixed a bug which was preventing to work on a local file by overwriting it with its processed copy
    - added MIME types video/x-ms-wmv and image/x-png and fixed PNG support for IE weird MIME types
    - modified image_ratio_crop so it can accept one or more from string ‘TBLR’, determining which side of the image is kept while cropping
    - added support for multiple lines in the text, using “\n” as a line break
    - added image_text_line_spacing which allow to set the space between several lines of text
    - added image_text_alignment which allow to set the alignment when text has several lines
    image_text_font can now be set to the path of a GDF font to load external fonts
    - added image_reflection_height to create a reflection of the source image, which height is in pixels or percentage
    - added image_reflection_space to set the space in pixels between the source image and the reflection
    - added image_reflection_color to set the reflection background color
    - added image_reflection_opacity to set the initial level of opacity of the reflection
  • v 0.21 30/09/2006
    - added image_ratio_crop which resizes within image_x and image_y, keeping ratio, but filling the space by cropping excedent of image
    - added mime_check, which default is true, to set checks against allowed MIME list
    - if MIME is empty, the class now triggers an error
    - color #000000 is OK for image_text_color, and related text transparency bug fixed
    - gd_version() now uses gd_info(), or else phpinfo()
    - fixed path issue when the destination path has no trailing slash on Windows systems
    - removed inline functions to be fully PHP5 compatible
  • v 0.20 11/08/2006
    - added some more error checking and messages (GD presence, permissions…)
    - fix when uploading files without extension
    - changed values for image_brightness and image_contrast to be between -127 and 127
    - added dir_auto_create to automatically and recursively create destination directory if missing.
    - added dir_auto_chmod to automatically chmod the destination directory if not writeable.
    - added dir_chmod to set the default chmod to use.
    - added image_crop to crop images
    - added image_negative to invert the colors on the image
    - added image_greyscale to turn the image into greyscale
    - added image_threshold to apply a threshold filter on the image
    - added image_bevelimage_bevel_color1 and image_bevel_color2 to add a bevel border
    - added image_border and image_border_color to add a single color border
    - added image_frame and image_frame_colors to add a multicolored frame
  • v 0.19 29/03/2006
    - class is now compatible i18n (thanks Sylwester).
    - the class can mow manipulate local files, not only uploaded files (instanciate the class with a local filename).
    file_safe_name has been improved a bit.
    - added image_brightnessimage_contrastimage_tint_colorimage_overlay_color andimage_overlay_percent to do color manipulation on the images.
    - added image_text and all derivated settings to add a text label on the image.
    - added image_watermark and all derivated settings to add a watermark image on the image.
    - added image_flip and image_rotate for more image manipulations
    - added jpeg_size to calculate the JPG compression quality in order to fit within one filesize.
  • v 0.18 02/02/2006
    - added no_script to turn dangerous scripts into text files.
    - added mime_magic_check to set the class to use mime_magic.
    - added preserve_transparency *experimental*. Thanks Gregor.
    - fixed size and mime checking, wasn’t working :/ Thanks Willem.
    - fixed memory leak when resizing images.
    - when resizing, it is not necessary anymore to set image_convert.
    - il is now possible to simply convert an image, with no resizing.
    - sets the default file_max_size to upload_max_filesize from php.ini. Thanks Edward
  • v 0.17 28/05/2005
    - the class can be used with any version of GD.
    - added security check on the file with a list of mime-types.
    - changed the license to GPL v2 only
  • v 0.16 19/05/2005
    - added file_auto_rename automatic file renaming if the same filename already exists.
    - added file_safe_name safe formatting of the filename (spaces to _underscores so far).
    - added some more error reporting to avoid crash if GD is not present
  • v 0.15 16/04/2005
    - added JPEG compression quality setting. Thanks Vad
  • v 0.14 14/03/2005
    - reworked the class file to allow parsing with phpDocumentor
  • v 0.13 07/03/2005
    - fixed a bug with image_ratio. Thanks Justin.
    - added image_ratio_no_zoom_in and image_ratio_no_zoom_out
  • v 0.12 21/01/2005
    - added image_ratio to resize within max values, keeping image ratio
  • v 0.11 22/08/2003
    - update for GD2 (changed imageresized() into imagecopyresampled() and imagecreate() into imagecreatetruecolor())

?boolean: Alias of CBooleanValidator, 只有true和 false
?captcha: Alias of CCaptchaValidator, 验证码验证
?compare: Alias of CCompareValidator, 对比表单里面的属性或者常量
?email: Alias of CEmailValidator, 确认是个正确的e-mail 地址
?default: Alias of CDefaultVAlidator, 按照默认值设置
?exist: Alias of CExistValidator, 确定可以从表的字段里面找到in the specified table column
?file: Alias of CFileValidator, 确定属性包括上传文件名an uploaded file,简单说就是确认有上传文件
?filter: Alias of CFilterValidator, transforming the attribute with a filter
?in: Alias of CRangeValidator, 在指定的列表里面存在
?length: Alias of CStringValidator, 大小限制
?match: Alias of CRegularExpressionValidator, 确定数据匹配一个正则表达式
?numerical: Alias of CNumberValidator, 确定是个有效数字
?required: Alias of CRequiredValidator, 确定不能为空
?type: Alias of CTypeValidator,确定属性是个特定的类型

?unique: Alias of CUniqueValidator, 确定字段在表里的列是唯一字段
?url: Alias of CUrlValidator, 确定是个正确的url

下面是个例子

public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('create_user_id, update_user_id', 'numerical','integerO
nly'
=>true),
array('name', 'length', 'max'=>128),
array('create_time, update_time', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, name, description, create_time, create_user_id,
update_time, update_user_id'
, 'safe', 'on'=>'search'),
array('name', 'required'),
);
}
By saving

yii 里面 gii 设置 modules 模块里面的model,以及各种配置图解

在执行

C:\>cd wamp\bin\php\php5.2.5

C:\wamp\bin\php\php5.2.5>go-pear.bat

会出现下面错误

phar “[path]go-pear.phar” does not have a signature
Warning: require_once(phar://go-pear.phar/index.php): failed to open stream: pha
r “[path]go-pear.phar” does not have a signature in [path]\PEAR\go-pear.phar on line 1236

Fatal error: require_once(): Failed opening required ‘phar://go-pear.phar/index.
php’ (include_path=’.;[path][path]\PEAR’) in [path]\PEAR\go-pear.phar on line 1236

解决方法:

进入:cd PEAR目录

然后执行:php.exe -d phar.require_hash=0 go-pear.phar

这样就可以顺利执行

1在view里面调用
echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //发送类型
'url'=>CController::createUrl('currentController/dynamiccities'), //要调用返回的php程序.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city_id', //选择这个菜单后下个菜单要变动
'data'=>'js:javascript statement'//默认提交市整个form的数据,如果使用这个参数,就只提交这个参数,例子:'data'=>array('province'=>"js:this.value")),

)));

//上面菜单变动后这个菜单根据变化

echo CHtml::dropDownList('city_id','', array());

这个是php代码部分

public function actionDynamiccities()
{
    $data=Location::model()->findAll('parent_id=:parent_id',
                  array(':parent_id'=>(int) $_POST['country_id']));

    $data=CHtml::listData($data,'id','name');
    foreach($data as $value=>$name)
    {
        echo CHtml::tag('option',
                   array('value'=>$value),CHtml::encode($name),true);
    }
}

下来菜单,默认选择值”selected”
$form->dropDownList($model,'sex',array('1'=>'men','2'=>'women'));
例如:

< select name="sex">
< option value="1">men

< option value="2" selected="selected">women

操作方法
$form->dropDownList($model,'sex',array('1'=>'men','2'=>'women'), array('options' => array('2'=>array('selected'=>true))));

About this blog

QK31欢迎你的到来.

Photostream