php下载文件简单实例

class Spider { public function downloadImage($url, $path='images/') { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); $file = curl_exec($ch); curl_close($ch); $this->saveAsImage($url, $file, $path); } private function saveAsImage($url, $file, $path) { $filename = pathinfo($url, PATHINFO_BASENAME); if(!file_exists($path)){ mkdir($path,0777); } $resource = fopen($path . $filename, 'a'); fwrite($resource, $file); fclose($resource); } } $str = file_get_contents("http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"); $arr = json_decode($str,true); $img_url = 'http://www.bing.com'.$arr['images'][0]['url']; $img = new Spider(); $img->downloadImage($img_url);

March 2, 2018 · 1 min · ZhaoGuibin

centOS7下安装GUI图形界面

1 .在命令行下 输入下面的命令来安装Gnome包。 yum groupinstall "GNOME Desktop" "Graphical Administration Tools" 2.在命令行输入startx进入桌面 startx 3.如果想开机就进桌面,那就更新系统的运行级别。 ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target 4.重启机器。启动默认进入图形界面。 reboot

February 9, 2018 · 1 min · ZhaoGuibin

vboxadd.sh failed modprobe vboxguest failed.

virtualbox安装增强功能报错: vboxadd.sh failed modprobe vboxguest failed. 解决方法: yum install dkms binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers then yum install kernel-devel or yum install kernel-PAE-devel Then re-run VBoxLinuxAdditions.run.

February 9, 2018 · 1 min · ZhaoGuibin

装完Centos7提示Initial setup of CentOS Linux 7 (core)

Initial setup of CentOS Linux 7 (core) 1) [x] Creat user 2) [!] License information (no user will be created) (license not accepted) Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: 解决方法: 输入“1”,按Enter键 输入“2”,按Enter键 输入“q",按Enter键 输入“yes”,按Enter键

February 9, 2018 · 1 min · ZhaoGuibin

linux安装pear

看图操作 这是错误,先放在前面,以免出现错误不知道怎么办 出现这个错误就按照它的那个地址下载现在在执行安装就好了 ...

January 20, 2018 · 1 min · ZhaoGuibin

php下安装event扩展

安装支持库libevent,需要编译高版本(这里以最新版本release-2.1.8-stable为例) wget -c https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz -P /opt/local/src cd /opt/local/src tar -zxvf libevent-2.1.8-stable.tar.gz && cd libevent-2.1.8-stable ./configure --prefix=/opt/local/libevent make && make install 安装event库(以event-2.3.0.tgz为例) wget -c http://pecl.php.net/get/event-2.3.0.tgz -P /opt/local/src cd /opt/local/src tar -zxvf event-2.3.0.tgz && cd event-2.3.0 /opt/local/php72/bin/bin/phpize ./configure --with-php-config=/opt/local/php72/bin/php-config --with-event-libevent-dir=/opt/local/libevent/ make && make install 在php.ini添加下面配置 extension=event.so

January 9, 2018 · 1 min · ZhaoGuibin

编译安装redis

一.安装Redis (1) cd /usr/src 进入下载目录 (1) yum install -y wget gcc make tcl 安装依赖 (2) redis官网http://www.redis.io下载最新的源码包 (3) tar -zxvf redis-3.2.2.tar.gz 解压 (4) cd redis-3.2.2 进入redis目录 (5) make 编辑 (6) make test 测试 测试过程报错 [exception]: Executing test client: NOREPLICAS Not enough good slaves to write.. NOREPLICAS Not enough good slaves to write. while executing 这种情况下,可以修改当前目录文件tests/integration/replication-2.tcl,将after 1000改为after 10000以延长等待时间 重新测试 (7)make install PREFIX=/usr/local/redis PREFIX安装指定目录 否则安装到/usr/local/bin里面了 (8)启动redis服务 ./redis-server ./redis-conf 发现很多错误: 1. WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128 echo 511 > /proc/sys/net/core/somaxconn 写到/etc/rc....

January 8, 2018 · 4 min · ZhaoGuibin

CentOS7下安装Python3及Pip3并保留Python2

安装依赖环境 yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel 浏览器打开 https://www.python.org/ftp/python/ 查看最新的Python版本,标记为3.A.B wget https://www.python.org/ftp/python/3.A.B/Python-3.A.B.tgz 创建Python3的目录 mkdir /usr/local/python3 解压下载文件并切换目录 tar -zxvf Python-3.A.B.tgz cd Python-3.A.B 执行 ./configure --prefix=/usr/local/python3 make && make install 创建Python3的软链接 ln -s /usr/local/python3/bin/python3 /usr/bin/python3 创建Pip3的软链接 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 测试命令 python3 和 pip3 python3 pip3 因为执行yum需要python2版本,所以我们还要修改yum的配置,执行: vim /usr/bin/yum 把#! /usr/bin/python修改为#! /usr/bin/python2 同理 vim /usr/libexec/urlgrabber-ext-down 文件里面的#! /usr/bin/python 也要修改为#! /usr/bin/python2 安装保留了原python命令调用python2 安装完成 ps 安装报错 Q: ModuleNotFoundError: No module named '_ctypes' A: yum -y install gcc gcc-c++ yum -y install zlib zlib-devel yum -y install libffi-devel Q:configure: error: no acceptable C compiler found in $PATH A:yum install gcc

January 2, 2018 · 1 min · ZhaoGuibin

解决"configure error no acceptable C compiler found in $PATH"

解决方法: 安装gcc yum install gcc

January 2, 2018 · 1 min · ZhaoGuibin

linux下php扩展mysqli的支持

mysqli是优化后的mysql,具体的优点baidu下就ok了 cd php-5.2.8 在这下面有个ext文件夹里有mysqli cd ext/mysqli linux下将源码文件编译应该都有configure吧,可这里没有,在我们已经安装php后,php5这个文件夹里的命令目录bin里有一个文件叫phpize,用它就可以生成configure文件啦,继续 /usr/local/php5/bin/phpize 这里回车运行,执行完后就出了configure文件, ./configure --prefix=/opt/local/mysqli --with-php-config=/opt/local/php/bin/php-config --with-mysqli=/opt/local/mysql/bin/mysql_config 直接回车,不出问题就继续。。 make make test make install (不出错就会显示Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20041030/) 现在mysqli.so文件就出来啦。。 直接在php.ini里把这个文件加载就OK啦。。 extension_dir=”/usr/local/php5/ext” extension=mysqli.so 把上面第一行找到修改成这个,然后再把第二行加入。。wq保存退出。 把mysqli.so这个文件cp到/usr/local/php5/ext下 重启apache.

December 3, 2017 · 1 min · ZhaoGuibin