exec: “pkg-config”: executable file not found in %PATH% 的解决办法

在windows下要用golang实现操作zeromq消息队列,发现在sublime下进行

go get -tags zmq_3_x github.com/alecthomas/gozmq

操作的时候,提示

# pkg-config –cflags libzmq libzmq libzmq libzmq
exec: “pkg-config”: executable file not found in %PATH%
exit status 2

原因是因为没有安装pkg-config.需要手动安装,并设置一下环境变量.pkg-config下载地址:http://ftp.acc.umu.se/pub/gnome/binaries/win32/dependencies/pkg-config_0.23-3_win32.zip (http://ftp.acc.umu.se/pub/gnome/binaries/win64/dependencies/pkg-config_0.23-2_win64.zip)

如果无法下载,直接打开所在的目录,找到合适的软件包下载.然后将包里bin目录里的pkg-config.exe放在一个目录,在新建一个"环境变量",变量名为 PKG_CONFIG_PATH .值为pkg-config.exe所在的目录即可. Continue reading

用golang发送邮件


配置文件 conf.json

{
"Username": "sunxxg@163.com",
"Password": "123456",
"Smtphost":"smtp.163.com:25"
}

主程序  sendmail.go

package main

import (
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/smtp"
	"os"
	"strings"
)

type cfgmail struct {
	Username string
	Password string
	Smtphost string
}

type cfg struct {
	Name, Text string
}

func main() {

	// 从json文件中读取发送邮件服务器配置信息
	cfgjson := getConf()

	var cfg cfgmail
	dec := json.NewDecoder(strings.NewReader(cfgjson))


	if err := dec.Decode(&cfg); err == io.EOF {
		break
	} else if err != nil {
		log.Fatal(err)
	}

	//fmt.Printf("%sn%sn%sn", cfg.Username, cfg.Password, cfg.Smtphost)


	username := cfg.Username
	password := cfg.Password
	host := cfg.Smtphost

	to := "10010@qq.com"

	fmt.Printf("============")
	fmt.Println(username)
	subject := "能否收到邮件哟?Test send email by golang"

	body := `
<html>
<body>
<h3>
"Test send email by golang,来个测试试一下"
</h3>
</body>
</html>
`
	err := SendMail(username, password, host, to, subject, body, "html")
	if err != nil {
		fmt.Println("send mail error!")
		fmt.Println(err)
	} else {
		fmt.Println("send mail success!")
	}

}

func SendMail(user, password, host, to, subject, body, mailtype string) error {
	hp := strings.Split(host, ":")
	auth := smtp.PlainAuth("", user, password, hp[0])
	var content_type string
	if mailtype == "html" {
		content_type = "Content-Type: text/" + mailtype + "; charset=UTF-8"
	} else {
		content_type = "Content-Type: text/plain" + "; charset=UTF-8"
	}

	msg := []byte("To: " + to + "rnFrom: " + user + "<" + user + ">rnSubject: " + subject + "rn" + content_type + "rnrn" + body)
	send_to := strings.Split(to, ";")
	err := smtp.SendMail(host, auth, user, send_to, msg)
	return err
}

func getConf() string {
	filename := "conf.json"
	file, err := os.Open(filename)

	defer file.Close()
	if err != nil {
		fmt.Println("read conf file error")
		log.Fatal(err)
	}

	buf := make([]byte, 512)
	var str1 string
	for {
		n, _ := file.Read(buf)
		if 0 == n {
			break
		}
		//os.Stdout.Write(buf[:n])

		str := string(buf[:n])

		str1 = str1 + str
	}
	return str1
}


然后执行

$ go run sendmail.go

即可.

对于一些文件的操作,可参考:https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/07.0.md

nginx日志切割

nginx的日志文件没有rotate功能。如果你不处理,日志文件将变得越来越大,还好我们可以写一个nginx日志切割脚本来自动切割日志文件。

第一步就是重命名日志文件,不用担心重命名后nginx找不到日志文件而丢失日志。在你未重新打开原名字的日志文件前,nginx还是会向你重命名的文件写日志,linux是靠文件描述符而不是文件名定位文件。 Continue reading

mysql中innodb表的count优化

作/译者:叶金荣(imysql#imysql.com>),来源:http://imysql.com,欢迎转载。

起因:在innodb表上做count(*)统计实在是太慢了,因此想办法看能不能再快点。
现象:先来看几个测试案例,如下
一、 sbtest 表上的测试

show create table sbtest\G
*************************** 1. row ***************************
Table: sbtest
Create Table: CREATE TABLE `sbtest` (
`aid` bigint(20) unsigned NOT NULL auto_increment,
`id` int(10) unsigned NOT NULL default '0',
`k` int(10) unsigned NOT NULL default '0',
`c` char(120) NOT NULL default '',
`pad` char(60) NOT NULL default '',
PRIMARY KEY  (`aid`),
KEY `k` (`k`),
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1000001 DEFAULT CHARSET=latin1

show index from sbtest;
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table  | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| sbtest |          0 | PRIMARY  |            1 | aid         | A         |     1000099 |     NULL | NULL   |      | BTREE      |         |
| sbtest |          1 | k        |            1 | k           | A         |          18 |     NULL | NULL   |      | BTREE      |         |
| sbtest |          1 | id       |            1 | id          | A         |     1000099 |     NULL | NULL   |      | BTREE      |         |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+

填充了 100万条 记录。

show index from 表名介绍:http://blog.haohtml.com/archives/1889 Continue reading

通过将session分布到多个目录里来提高网站访问速度

如果一个网站的session量特别大的话,且所有的session文件都在同一个子目录下的话,那么可能会由此带来很严重的负载问题,甚至导致网站无法使用。本文就是对这个方案做一下详细的解说。
首先,修改 php.ini的 session.save_path 选项,大致如下:

session.save_path = "3;/tmp/php_sess"

意为把session存放在 "/tmp/php_sess" 目录下,并且分成 3 级子目录,每级子目录又分多个子目录。

Continue reading

Linux下安装php开发框架yaf

https://github.com/laruence/php-yaf

yaf框架中文手册:http://yaf.laruence.com/manual/index.html

yaf手册:http://www.php.net/manual/en/book.yaf.php

1.下载并安装yaf扩展 http://pecl.php.net/package/yaf

#wget http://pecl.php.net/get/yaf-2.2.9.tgz
#tar zxvf yaf-2.2.9.tgz
#cd yaf-2.2.9

[root@bogon yaf-2.2.9]# whereis phpize
phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz
/usr/bin/phpize

[root@bogon yaf-2.2.9]# /usr/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
#whereis php-config
php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz

#./configure --with-php-config=/usr/bin/php-config
#make && make install

2.添加扩展配置到php.ini

在/etc/php.ini文件里添加一行

extension=yaf.so

重启webserver 即可.

===========================
如果在./configure的时候遇到以下错误:

configure: error: in `/root/yaf-2.2.9′:configure: error: no acceptable C compiler found in $PATHSee `config.log’ for more details.

说明,没有安装gcc.用 yum -y install gcc 安装一下即可.