Drupal7零散的筆記
使用 Nginx FastCGI 生成AMP快取的conf
我的語法,由於我的頁面本身就有drupal的快取服務,但這個快取服務在amp起不了作用,所以才使用這招
作法就是只讓有*?amp產出快取;另外還要研究登入使用者不用快取,可能要研究drupal的cookie吧?
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=tainanoutook:200m max_size=10g inactive=2h use_temp_path=off;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
set $skip_cache 1;
if ($request_uri ~* "/.*?amp") {
set $skip_cache 0;
}
include snippets/fastcgi-php.conf;
fastcgi_cache tainanoutook;
fastcgi_cache_valid 200 301 302 2h;
fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
fastcgi_cache_min_uses 1;
fastcgi_cache_lock on;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
add_header X-FastCGI-Cache $upstream_cache_status;
Drupal7 Optimizing 優化速度
使用模組 chained_fast apcu registry_autoload xautoload
drush en chained_fast apcu registry_autoload xautoload expire -y
vi sites/default/settings.php
$conf['cache_backends'][] = 'sites/all/modules/apcu/apcu.cache.inc';
$conf['cache_backends'][] = 'sites/all/modules/chained_fast/chained_fast.cache.inc';
// Chained fast configuration.
$conf['chained_fast']['fast_backend'] = 'DrupalAPCuCache';
// Cache class configuration - This uses chained_fast for all caches except the form cache. This might not be suitable for all sites, but is a good default.
$conf['cache_default_class'] = 'ChainedFastBackend';
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
admin/config/development/performance 下列全打勾
匿名使用者頁面快取
區塊快取
壓縮快取頁面
整合並壓縮 CSS 檔案
整合並壓縮 JavaScript 檔案
Self-updating APCu classmap (*) (Running and available)
APC (Running and available)
APCu (Running and available)
XCache (Not currently available)
Self-updating database classmap (*) (Running and available)
Postpone registration of module namespaces until the first cache miss (recommended)
Replace core class loader.
expire (Cache Expiration) 這個模組主要在控管內容更新後會清除快取
Status of implementation 勾選 Internal expiration
Modules that support external expiration 勾選 Include base URL in expires
Node expiration Node actions 全勾選
PS. 重要文章更新後,最好再用未登入的瀏覽器確認一次,如果內容仍然無法更新,就直接清除Drupal全站快取囉
Views PHP
Drupal 7能夠方便在views執行php的模組 https://www.drupal.org/project/views_php
顯示某個欄位內容 : field_dow
<?php
// 假設 $data 是你已經從資料庫或其他來源獲取的資料
$field_dow = $data->_field_data['nid']['entity']->field_dow['und'];
// 提取 [field_dow] 內的值
$dow_values = array_map(function($item) {
return $item['value'];
}, $field_dow);
// 印出結果
echo implode(', ', $dow_values);
?>
field_dow 的值為 1 ~ 7,接下來轉換成 一 ~ 日(星期)
<?php
// 假設 $data 是你已經從資料庫或其他來源獲取的資料
$field_dow = $data->_field_data['nid']['entity']->field_dow['und'];
// 數字對應的星期轉換表
$weekdays = [
1 => '一',
2 => '二',
3 => '三',
4 => '四',
5 => '五',
6 => '六',
7 => '日'
];
// 提取 [field_dow] 內的值並轉換成星期
$dow_names = array_map(function($item) use ($weekdays) {
return $weekdays[$item['value']];
}, $field_dow);
// 印出結果
echo implode(', ', $dow_names);
?>
我的站有一個功能是在撈夜市的的時間,例如今天是星期五,他就會只顯示星期五的夜市
使用 Views Day of Week (views_dow) 達成的,但由於他預出來的值是英文,不動原始碼的情況,就用這個作法去處理