工作,学习,生活,这里将会有一些记录. 备用域名:http://meisw.wdlinux.cn 注册 | 登陆
浏览模式: 标准 | 列表全部文章

php获取远程图片并把它保存到本地

<?php
//
// Function: 获取远程图片并把它保存到本地
//
//
// 确定您有把文件写入本地服务器的权限
//
//
// 变量说明:
// $url 是远程图片的完整URL地址,不能为空。
// $filename 是可选变量: 如果为空,本地文件名将基于时间和日期
// 自动生成.
function GrabImage($url,$filename="") {
if($url==""):return false;endif;
if($filename=="") {
$ext=strrchr($url,".");
if($ext!=".gif" && $ext!=".jpg"):return false;endif;
$filename=date("dMYHis").$ext;
}
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2=@fopen($filename, "a");
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}
$img=GrabImage("http://tech.51099.com/_1978837_detector_ap100.jpg","");
if($img):echo '<pre><img src="'.$img.'"></pre>';
else:echo "false";
endif;
?>

命令一句话(整理) 转

命令一句话(整理)更新

1.删除0字节文件
find -type f -size 0 -exec rm -rf {} \;

2.查看进程
内存从大到小排列
ps -e

-o "%C : %p : %z : %a"|sort -k5 -nr

3.按cpu利用率从大到小排列
ps -e -o "%C : %p : %z : %a"|sort -nr

4.打印说cache里的URL
grep -r -a jpg /data/cache/* | strings | grep "http:" | awk -F'http:' '{print "http:"$2;}'

5.查看http的并发请求数及其TCP连接状态:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

---------------------------------------------------------------------------------------
1. sed -i '/Root/s/no/yes/' /etc/ssh/sshd_config sed在这个文里Root的一行,匹配Root一行,将no替换成yes.

2.1.如何杀掉mysql进程:
ps aux|grep mysql|grep -v grep|awk '{print $2}'|xargs kill -9 (从中了解到awk的用途)

killall -TERM mysqld

kill -9 `cat /usr/local/apache2/logs/httpd.pid` 试试查杀进程PID



3.显示运行3级别开启的服务:
ls /etc/rc3.d/S* |cut -c 15- (从中了解到cut的用途,截取数据)

4.如何在编写SHELL显示多个信息,用EOF
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Tunoff services === |
+--------------------------------------------------------------+
EOF

5. for 的巧用(如给mysql建软链接)
cd /usr/local/mysql/bin
for i in *
do ln /usr/local/mysql/bin/$i /usr/bin/$i
done

6. 取IP地址:
ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6- 或者

ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'

7.内存的大小:
free -m |grep "Mem" | awk '{print $2}'


8.
netstat -an -t | grep ":80" | grep ESTABLISHED | awk '{printf "%s %s\n",$5,$6}' | sort

9.查看Apache的并发请求数及其TCP连接状态:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

10.因为同事要统计一下服务器下面所有的jpg的文件的大小,写了个shell给他来统计.原来用xargs实现,但他一次处理一部分,搞的有多个总和....,下面的命令就能解决啦.
find / -name *.jpg -exec wc -c {} \;|awk '{print $1}'|awk '{a+=$1}END{print a}'


CPU的数量(多核算多个CPU,cat /proc/cpuinfo |grep -c processor)越多,系统负载越低,每秒能处理的请求数也越多。

--------------------------------------------------------------------------------------------------------------------
1 CPU负载 # cat /proc/loadavg
检查前三个输出值是否超过了系统逻辑CPU的4倍。

2 CPU负载 #mpstat 1 1
检查%idle是否过低(比如小于5%)
3 内存空间 # free
检查free值是否过低 也可以用 # cat /proc/meminfo
4 swap空间 # free
检查swap used值是否过高 如果swap used值过高,进一步检查swap动作是否频繁:
# vmstat 1 5
观察si和so值是否较大
5 磁盘空间 # df -h
检查是否有分区使用率(Use%)过高(比如超过90%) 如发现某个分区空间接近用尽,可以进入该分区的挂载点,用以下命令找出占用空间最多的文件或目录:
# du -cks * | sort -rn | head -n 10
6 磁盘I/O负载 # iostat -x 1 2
检查I/O使用率(%util)是否超过100%
7 网络负载 # sar -n DEV
检查网络流量(rxbyt/s, txbyt/s)是否过高
8 网络错误 # netstat -i
检查是否有网络错误(drop fifo colls carrier) 也可以用命令:# cat /proc/net/dev
9 网络连接数目 # netstat -an | grep -E “^(tcp)” | cut -c 68- | sort | uniq -c | sort -n
10 进程总数 # ps aux | wc -l
检查进程个数是否正常 (比如超过250)
11 可运行进程数目 # vmwtat 1 5
r列给出的是可运行进程的数目,检查其是否超过系统逻辑CPU的4倍
12 线程数目
13 进程 # top -id 1
观察是否有异常进程出现
14 网络状态 检查DNS, 网关等是否可以正常连通
15 用户 # who | wc -l
检查登录用户是否过多 (比如超过50个) 也可以用命令:# uptime
16 系统日志 # cat /var/log/rflogview/*errors
检查是否有异常错误记录 也可以搜寻一些异常关键字,例如:
# grep -i error /var/log/messages
# grep -i fail /var/log/messages
17 核心日志 # dmesg
检查是否有异常错误记录
18 系统时间 # date
检查系统时间是否正确
19 打开文件数目 # lsof | wc -l
检查打开文件总数是否过多
20 日志 # logwatch –print 配置/etc/log.d/logwatch.conf,将 Mailto 设置为自己的email 地址,启动mail服务 (sendmail或者postfix),这样就可以每天收到日志报告了。
缺省logwatch只报告昨天的日志,可以用# logwatch –print –range all 获得所有的日志分析结果。
可以用# logwatch –print –detail high 获得更具体的日志分析结果(而不仅仅是出错日志)。

21.杀掉80端口相关的进程
lsof -i :80|grep -v "PID"|awk '{print "kill -9",$2}'|sh

22.清除僵死进程。
ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9

apache+ssl

安装升级ssl
rpm -qa | grep "openssl"
yum update openssl


http://labs.xiaonei.com/apache-mirror/httpd/httpd-2.0.63.tar.gz
http://cn2.php.net/get/php-5.3.0.tar.gz/from/this/mirror
http://cn.php.net/get/php-5.2.10.tar.gz/from/cn2.php.net/mirror
http://www.openssl.org/source/openssl-0.9.8k.tar.gz

openssl
tar && cd
./config;make;make install

tar && cd
./configure --prefix=/www/servers/httpd20 --enable-so --with-rewrite --enable-expires --enable-ssl --with-ssl=/usr
or
./configure --prefix=/www/servers/httpd20 --enable-so --enable-ssl=static --with-ssl=/usr/local/ssl

make;make install


php (5.3无法解释PHP)
tar && cd
./configure --prefix=/www/servers/php5 --with-apxs2=/www/servers/httpd201/bin/apxs --with-mysql=/www/servers/mysql5 --with-gd=/usr/local/gd --enable-gd-native-ttf --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr --enable-gd-native-ttf --with-zlib --with-freetype-dir=/usr/local/freetype --with-iconv --enable-mbstring --enable-ftp

 


faq
Q:
Session Cache is not configured

Q:
打开网页提示选择证书
A:
ssl.conf
SSLVerifyClient require
SSLVerifyDepth  10


URL:
http://snailwarrior.blog.51cto.com/680306/137657
http://www.javayou.com/diary/617

IE7下window.close()不提示的解决方法

<script langanue=javascript>alert('事件已提交存档!');window.opener = null;window.open('','_self','');window.close();</script>

<a onclick="window.opener=null;window.open('','_self','');window.close();" href="javascript:void(0);"> 关闭不提示 </a>              

关键是window.open('','_self','')

dede:pub_db_mysql

$dsql=new DedeSql(false);
$dsql->SetQuery("sql");
$dsql->Execute();
$row=$dsql->GetObject();//一行 $dsql->GetArray()
while ($row=$dsql->GetObject()) {};//循环
//result
$row->id,$row->name;//$row['d'],$row['name']


//一行
$dsql=new DedeSql(false);
$row=$dsql->GetOne("");
$row['id'];

//无返回
$dsql=new DedeSql(false);
$dsql->ExecuteNoneQuery("");

 

//相关信息
$dsql=new DedeSql(false);
$dsql->GetError();
$dsql->Version();
$dsql->Close();
$dsql->FreeResult();
$dsql->GetLastID();
$dsql->GetTotalRow();
$dsql->IsTable(table);

require_once(dirname(__FILE__)."/include/config_base.php");

smem: 内存占用报告

smem 能够为你报告内存的占用情况,提供 PID、User、Command、Swap、USS、PSS、RSS 等信息。除了一般的文本信息报告外,smem 也可以生成条状或饼状图。

通过 smem --help 可以获得它的使用说明。

smem 要求 Kernel 2.6.27/Python 2.4 及以上版本、matplotlib 库。

smem

rhel 使用 centos 源升级

redhat 4

http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/yum-2.4.3-4.el4.centos.noarch.rpm
rpm -ivh yum-2.4.3-4.el4.centos.noarch.rpm
warning: yum-2.4.3-4.el4.centos.noarch.rpm: V3 DSA signature: NOKEY, key ID 443e1821
error: Failed dependencies:
        python-elementtree is needed by yum-2.4.3-4.el4.centos.noarch
        python-sqlite is needed by yum-2.4.3-4.el4.centos.noarch
        urlgrabber is needed by yum-2.4.3-4.el4.centos.noarch
        yum-metadata-parser is needed by yum-2.4.3-4.el4.centos.noarch
        yumconf is needed by yum-2.4.3-4.el4.centos.noarch


http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/yum-metadata-parser-1.0-8.el4.centos.i386.rpm
rpm -ivh yum-metadata-parser-1.0-8.el4.centos.i386.rpm
warning: yum-metadata-parser-1.0-8.el4.centos.i386.rpm: V3 DSA signature: NOKEY, key ID 443e1821
error: Failed dependencies:
        libsqlite3.so.0 is needed by yum-metadata-parser-1.0-8.el4.centos.i386


http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/sqlite-3.3.6-2.i386.rpm
rpm -ivh sqlite-3.3.6-2.i386.rpm
warning: sqlite-3.3.6-2.i386.rpm: V3 DSA signature: NOKEY, key ID 443e1821
Preparing...                ########################################### [100%]
   1:sqlite                 ########################################### [100%]


http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/python-sqlite-1.1.7-1.2.1.i386.rpm
http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/python-elementtree-1.2.6-5.el4.centos.i386.rpm
http://mirror.centos.org/centos-4/4.7/os/i386/CentOS/RPMS/python-urlgrabber-2.9.8-2.noarch.rpm
rpm -ivh python-*
warning: python-elementtree-1.2.6-5.el4.centos.i386.rpm: V3 DSA signature: NOKEY, key ID 443e1821
Preparing...                ########################################### [100%]
   1:python-urlgrabber      ########################################### [ 33%]
   2:python-elementtree     ########################################### [ 67%]
   3:python-sqlite          ########################################### [100%]


ftp://ftp.isu.edu.tw/pub/Linux/CentOS/4.7/os/ia64/CentOS/RPMS/centos-yumconf-4-4.5.noarch.rpm
http://rpm.pbone.net/index.php3/stat/4/idpl/2665731/com/centos-yumconf-4-4.5.noarch.rpm.html
rpm -ivh


配置
vi /etc/yum.repos.d/CentOS-Base.repo

[base]
name=Red Hat Enterprise As release 4 base
baseurl=http://mirror.centos.org/centos-4/4.7/os/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos-4/4.7/os/i386/RPM-GPG-KEY-centos4
[update]
name=Red Hat Enterprise As release 4 updates
baseurl=http://mirror.centos.org/centos-4/4.7/updates/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos-4/4.7/os/i386/RPM-GPG-KEY-centos4
[extras]
name=Red Hat Enterprise As release 4 extras
baseurl=http://mirror.centos.org/centos-4/4.7/extras/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos-4/4.7/os/i386/RPM-GPG-KEY-centos4


rhel 5

rhel 5 系统上已有支持并安装yum,但是要用到rh本身的更新服务,如果没买就用不了。
只需要把 /etc/yum.repos.d/rhel-debuginfo.repo 里的内容,替换为centos 5 的就可以了。
把上面的4.7替换为 5.3即可

如果在装系统时没有装上yum,则另外安装
如下,根据依赖关系,安装所有的包

rpm -ivh yum-3.2.19-18.el5.centos.noarch.rpm
warning: yum-3.2.19-18.el5.centos.noarch.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
error: Failed dependencies:
        yum-rhn-plugin < 0.5.2-1.el5 conflicts with yum-3.2.19-18.el5.centos.noarch

此包可以不安装,加个--nodeps参数直接安装yum
一样可以正常使用yum更新,但都是用centos的源

 

---------------------
mkdir yum;cd yum;wget http://...198/rhel_yum_soft.tar.gz;tar zxvf rhel_yum_soft.tar.gz;rpm -ivh *.rpm;cp CentOS-Base.repo

/etc/yum.repos.d/;cd ..;rm -fr yum;yum update -y udev;

mysql热备

http://database.51cto.com/art/200510/8434.htm
http://imysql.cn/node/56
http://yemaosheng.com/?p=86


setup

要求mysql的版本比较接近

master my.cnf
[mysqld]
log-bin
server-id=1

master
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.mydomain.com' IDENTIFIED BY 'slavepass';

restart mysql;

FLUSH TABLES WITH READ LOCK;

tar zcvf mysql-snapshot.tar.gz .

cp tar.gz to slave

tar zxvf tar.gz

show master status;

UNLOCK TABLES;

slave my.cnf
[mysqld]
server-id=slave_id

slave
CHANGE MASTER TO MASTER_HOST='master_host_name',MASTER_USER='replication_user_name',MASTER_PASSWORD='replication_password',MASTER_LOG_FILE='recorded_log_file_name',MASTER_LOG_POS=recorded_log_position;

start slave;