ThinkPHP 使用 WorkerMan 的一些记录

通过 composer 安装

composer require topthink/think-worker

启动

php think worker

初次使用可能会报错

[root@instance-jewlel2q www.imgram.cn]# php think worker
Starting Workerman http server...
Workerman[think] start in DEBUG mode
stream_socket_server() has been disabled for security reasons in file[......]

Read more

MySQL 导出 xls

若查询语句为

SELECT *,count(*) as count FROM `youhui_activity_log` WHERE `type`="activity_21_page_index" AND `value`="c8" AND DATE_FORMAT(`create_time`,"%Y-%m-%d")= "2018-12-06" GROUP BY `key`;

则导出语句为

SELECT *,count(*) as count FROM `youhui_activity_log` WHERE `type`="activity_21_page_index" AND[......]

Read more

一些 JavaScript JS 函数

数字前补零

function PrefixInteger(num, length) {
        return (Array(length).join('0') + num).slice(-length);
}

简单使用 Scrapy

新建项目

新建项目 douban

scrapy startproject douban

生成爬虫主文件

cd douban
scrapy genspider douban_spider movie.douban.com

明确目标,编写 items 文件

spider 文件的编写

测试下抓取

scrapy crawl douban_spider

Windows 版提示错误 ModuleNotFoundError: No module named ‘win32api’

解决办法:安装 pywin32[……]

Read more

yum 安装 MongoDB 3.6

安装步骤

CentOS7 直接 yum 安装 会出现 No package mongodb-org available.

首先,编辑 MongoDB 安装源

vim /etc/yum.repos.d/mongo.repo

然后粘贴如下内容并保存退出

[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=h[......]

Read more

Win10 安装 Python3 Scrapy

下载安装 Python3

https://www.python.org/ftp/python/3.7.1/python-3.7.1-amd64.exe

安装完成后 

pip3 install scrapy

报错

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

解决方法:安装 Microso[……]

Read more

CentOS 7 安装 Python3 与 Python2共存

CentOS 7 已经默认安装 Python 2.7.5 , 使用 Python -V 可查看当前版本,使用 which python 查看当前 Python 文件的可执行文件位置

编译前先安装常用相关包

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

然后下载安装包编译

cd ~
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2[......]

Read more

fSelect.js select 下拉多选框 checkbox 的使用方法

<!DOCTYPE html>
<html>
<head>
	<link href="jquery.fSelect.css" rel="stylesheet" type="text/css" />
	<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
	<script src="jquery.fSelect.js"></script>
	<script>
		$(function() {
			$('.demo').fSelect();
		});
	</scr[......]

Read more

简单测试一下 PHP mt_rand( ) 函数一秒钟重复值

<?php
echo "<pre>";

$start = microtime(true);
$end = microtime(true);
$rand = [];
$i = 0;
do{
    $theRand = mt_rand(0,99999);
    if(in_array($theRand,$rand)){
        $i=$i+1;
    }
    $rand[] = $theRand;
    $end = microtime(true);
}while(($end-$start)<1);

echo $i;
echo "<br>";
echo[......]

Read more

一些 PHP 函数

两个日期之间的全部日期

//两个日期之间的日期数组形式
function prDates($start,$end){
	$dt_start = strtotime($start);
	$dt_end = strtotime($end);
	$date = array();
	while ($dt_start<=$dt_end){
		$date[] = date('Y-m-d',$dt_start);
		$dt_start = strtotime('+1 day',$dt_start);
	}
	return $date;
}