Tag Archive: Drupal

启用了 Boost 模块缓存整个网站,或者需要在站外调用 Drupal 网站的数据,如何调用 Drupal 中的动态数据?

Ajax 调用 Drupal 中的 block 需要以下步骤

  • 启动 Drupal 页面
  • 动态输出 block 的内容,json 格式或者 html 格式
  • 在目标页面中 Jquery 输出 Ajax 调用的数据

启动 Drupal 输出HTML格式内容

1
2
3
4
5
6
7
<?php
// block.php
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$block = module_invoke('statistics', 'block', 'view', 0);
print $block['content'];
?>

在目标页面中 Jquery 输出 Ajax 调用的数据

1
2
3
4
<div id="info"></div>
<script>
$('#info').load('/block.php')
</script>

Drupal upload progress

Drupal filefield provide a upload progress bar when you uploding files. You should install APC upload progress module or PECL uploadprogress module.

PHP 5.2+ should be updated if you use APC as the upload progress system. The detailed instruction you can find at IBM’s guide.

PECL uplaod progress module can be find at http://pecl.php.net/package/uploadprogress/

Or install just a command line: pecl install uploadprogress.  Then Add extension=uploadprogress.so to php.ini, restart your Apache Server. This module is suggested.

All these modules must install with Apache Server.

Nginx upload progress Module

Nginx also provide the upload progress system. If this module are enabled, all upload files will be cached in Nginx before the whole file is uploaded.

Nginx buffers the entire upload before passing it to the php backend. So if you chose Nginx as the HTTP server or Proxy at the front of Apache Server, the Drupal upload progress will not work!

But the Nginx upload system is so brilliant that it will reduce the stress to the PHP backend, so your Server will be more stable and fast.

How to use Nginx upload progress module with Drupal uploading progress bar:

1. APC progress or PECL progress module are NOT required, because we use Nginx upload progress moudle.

2. You should install filefield_nginx_progress module in Drupal

3. You should compile Nginx with HttpUploadProgressModule

./configure –add-module=/www/nginx_uploadprogress_module

4. Configure in php.ini with upload file size limit and post size limit.

post_max_size = 2000M

upload_max_filesize = 2000M

5. Sample Nginx configuration file:

Apache as the back end server at port 81, Nginx as the proxy at port 80. Your domain name is www1.dev

http {
    client_max_body_size 2000M;
    client_body_buffer_size 128k;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    upload_progress uploads 1m;

    #gzip  on;

    server {
        listen       80;
        server_name  www1.dev;

	location ~ (.*)/x-progress-id:(\w*) {
            rewrite ^(.*)/x-progress-id:(\w*)  $1?X-Progress-ID=$2;
        }

        location ^~ /progress {
            report_uploads uploads;
        }

	location / {
	   proxy_set_header    X-Real-IP  $remote_addr;
	   proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
	   proxy_set_header    Host $http_host;

	   proxy_pass          http://127.0.0.1:81;
	   proxy_redirect      default;
	   add_header        X-Test Proxied;  # for diagnosis only - can be removed

	   track_uploads uploads 60s;
	}

	# serve static files directly
	location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
	   root /www/docs/www1.dev/drupal-6.x-dev;
	   access_log        off;
           expires           30d;
           add_header        X-Test Direct;  # for diagnosis only - can be removed
	}
    }
}

Drupal nginx progress module: http://drupal.org/project/filefield_nginx_progress

Nginx upload progress module: https://github.com/masterzen/nginx-upload-progress-module

Instruction about Drupal nginx uploading progress module:

http://drupalcode.org/viewvc/drupal/contributions/modules/filefield_nginx_progress/README.txt?view=co&pathrev=DRUPAL-6–1

Drupal 高效部署和维护

Drupal 是由很小的核心和几千个实现不同功能的模块组成,无论要实现什么功能,几乎都可以通过找到模块来实现。但是一个中等的系统会需要几十个或者上百个模块。所以Drupal 模块的部署和维护必须通过高效的方式来实现。

Drupal 提供了两种不同的部署方式,你可以通过命令行来部署,或者通过传统的WEB界面来维护。

本文只介绍命令行的方式。Drupal 有命令行维护工具 Drush 。通过Drush来维护系统是Drupal众多优秀的特性之一,它类似于Django中命令行自动生成数据库结构,或者PECL安装PHP的扩展模块,或者yum来维护Linux软件包。只需要一行命令就可以安装系统,或者下载一个模块。

1. Drush的安装:

对于Drupal6.x,下载Drush模块,并且解压即可:

$ cd ~

$ wget http://ftp.drupal.org/files/projects/drush-6.x-3.3.tar.gz

$ tar zxvf drush-6.x-3.3.tar.gz

$ ln -s /path/to/drush/drush /usr/local/bin/drush

这样你可以在任何目录执行drush命令。

2. 用Drush来下载安装Drupal:

你不需要从Drupal网站下载安装包,上传到FTP,再配置数据库,从WEB界面安装:

下载并且解压Drupal包:

$ drush dl

安装Drupal

$ drush is

安装CCK

$ drush dl cck

$ drush en cck

清空cache可能是开发中最常用的功能:

$ drush cc

查看watchdog信息:

$ drush ws

执行cron

$ drush cron

更多drush命令:http://drush.ws

推荐用Drush来部署和维护Drupal

所有模块的安装维护仅仅需要1-2行命令,不必在忍受WEB界面网速的问题。我们需要用最好最快的方式来节约时间,提高效率。