好處:
https://scalegrid.io/blog/postgresql-connection-pooling-part-4-pgbouncer-vs-pgpool/
https://medium.com/pgsql-tw/you-need-pgbouncer-e62fa329b209

安裝:
https://mydbops.wordpress.com/2020/03/25/getting-started-with-pgbouncer-in-postgresql/

# 編輯配置 -  這邊只列出需要注意部分
vi /etc/pgbouncer/pgbouncer.ini
[databases]
* = host=localhost
[pgbouncer]
listen_addr = *
listen_port = 6432
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
pool_mode = transaction# 產生檔案 /etc/pgbouncer/userlist.txt…

安裝postgreSQL的排程工具pgAgent

安裝套件

修改 pgagent 配置

DBNAME=postgres
DBUSER=postgres
DBHOST=127.0.0.1
DBPORT=5432
PASSWORD=你的密碼 # 新增
LOGFILE=/var/log/pgagent_12.log
vi /usr/lib/systemd/system/pgagent_12.service
--- 新增 password
ExecStart=/usr/bin/pgagent_12 -s ${LOGFILE} hostaddr=${DBHOST} dbname=${DBNAME} user=${DBUSER} port=${DBPORT} password=${PASSWORD}----

修改 pg_hba.conf

# IPv4 local connections:
host all all 127.0.0.1/32 md5 # 原 ident

安裝pgAdmin管理套件pgagent

psql -Upostgres CREATE EXTENSION pgagent;

啟動服務

pgAdmin畫面

— 完成 —

在開發微服務時需要“服務發現”的測試環境,這邊使用consul

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install consul

配置系統服務

啟動服務

查看服務

— 完成 —

今日主題:最近在做內容網站需要將某個網站頁面上資料整理後寫入資料庫。

範例
$ch = curl_init();curl_setopt($ch, CURLOPT_USERAGENT, $USERAGENT);
curl_setopt($ch, CURLOPT_URL, "https://www.banpresto.jp/cn/kuji/9027060.html"); # 內容網站curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
if (isset($_SERVER) && isset($_SERVER['HTTP_USER_AGENT'])) {
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
}
$html = curl_exec($ch);
curl_close($ch);
//var_dump($output);# 解析
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
# 取得圖片
$imgList = $xpath->query('//section[@class="product-content"]/div/figure/a/img');
# 取得標題
$captionList = $xpath->query('//section[@class="product-content"]/div/figure/a/figcaption/p');
# XPath
//'//section[@class="product-content"]/div/figure/a/img'
//'//section[@class="product-content"]/div/figure/a/figcaption/p# 轉換成陣列
$srcList = [];
foreach ($imgList as $ix => $node) {$srcList[] = [
'caption' => $captionList[$ix]->nodeValue,
'img' => $node->attributes->getNamedItem('src')->nodeValue
];
}print_r($srcList);

如何取得XPath

今日主題:預設的驗證訊息是 resources/lang/xx-xx/validation.php(這邊要看config/app.php的locale的設定)對應rules產生的驗證訊息,例如:required、unique、…

這邊說明“custom”、“attributes”欄位
$validate = Validator::make(Input::all(), [
'g-recaptcha-response' => 'required|captcha'
]);
# required 會對應到 custom => 'g-recaptcha-response' => 'required'

今日主題: 製造關於Map應用時,會使用使用者經緯度與DB的經緯度進行距離轉換,然後將使用者附近的例如100公尺的餐廳顯示在地圖上。

M$ SQL Server

@Latitude1 float,@Longitude1 float,@Latitude2 float,@Longi …

hsuan-ming Yang

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store