几个免费的cdn图片站

curl ‘http://www.ugirls.com/Ajax/User/uploadAvator’ \
-H ‘Origin: http://www.ugirls.com’ \
-H ‘Accept-Encoding: gzip, deflate’ \
-H ‘Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7,ja;q=0.6′ \
-H ‘Upgrade-Insecure-Requests: 1′ \
-H ‘User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36′ \
-H ‘Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8′ \
-H ‘Cache-Control: no-cache’ \
-H ‘Referer: http://www.ugirls.com/Users/Info/’ \
-H ‘Connection: keep-alive’ \
-F “fileAvator=@/Users/wenzg/Pictures/kitty.jpg” –compresse \

curl ‘http://www.sinacloud.com/home/File/upload/url/1′ \
-H ‘User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36′ \
-H ‘Referer: http://www.sinacloud.com/ucenter/workorderadd.html’ \
-F “attachement=@/Users/wenzg/Pictures/kitty.jpg” –compressed

发表在 漏洞 | 留下评论

XHProf指标解释

主要指标:
Inclusive Time (或子树时间):包括子函数所有执行时间。
Exclusive Time/Self Time:函数执行本身花费的时间,不包括子树执行时间。
Wall时间:花去了的时间或挂钟时间。
CPU时间:用户耗的时间+内核耗的时间

# 如果xhprof_enable函数写作:xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY)可以输出更多指标。
Function Name 函数名
Calls 调用次数
Calls% 调用百分比

# 消耗时间
Incl. Wall Time (microsec) 调用的包括子函数所有花费时间 以微秒算(一百万分之一秒)
IWall% 调用的包括子函数所有花费时间的百分比
Excl. Wall Time (microsec) 函数执行本身花费的时间,不包括子树执行时间,以微秒算(一百万分之一秒)
EWall% 函数执行本身花费的时间的百分比,不包括子树执行时间

# 消耗CPU
Incl. CPU(microsecs) 调用的包括子函数所有花费的cpu时间。减Incl. Wall Time即为等待cpu的时间
ICpu% Incl. CPU(microsecs)的百分比
Excl. CPU(microsec) 函数执行本身花费的cpu时间,不包括子树执行时间,以微秒算(一百万分之一秒)。
ECPU% Excl. CPU(microsec)的百分比

# 消耗内存
Incl.MemUse(bytes) 包括子函数执行使用的内存。
IMemUse% Incl.MemUse(bytes)的百分比
Excl.MemUse(bytes) 函数执行本身内存,以字节算
EMemUse% Excl.MemUse(bytes)的百分比

# 消耗内存峰值
Incl.PeakMemUse(bytes) Incl.MemUse的峰值
IPeakMemUse% Incl.PeakMemUse(bytes) 的峰值百分比
Excl.PeakMemUse(bytes) Excl.MemUse的峰值
EPeakMemUse% EMemUse% 峰值百分比

发表在 php | 留下评论

php cli 文件下载进度

源码下载,参考自composer
downloadProcess.tar

发表在 扒拉代码 | 留下评论

PHP的几种运行外部命令的方式

有四种执行脚本的内置函数:
1、system
2、exec
3、pcntl_exec
4、passthru

发表在 涨姿势 | 留下评论

状态模式

流程图
流程图

类图
UML


/**
* Filename: test.php.
* User: George
* Date: 2017/12/24
* Time: 下午8:58
*/

// 请假系统

class LeaveRequesModel {
private $user = null; //请假人
private $beginDate = null; //请假开始时间
private $leaveDays = 0; //请假天数
private $result; //审核结果

public function setUser(string $user = '') {
$this->user = $user;
}

public function getUser() {
return $this->user;
}

public function setBeginDate(string $begin_date = '') {
$this->beginDate = $begin_date;
}

public function getBeginDate() {
return $this->beginDate;
}

public function setLeaveDays(int $leave_days = 0) {
$this->leaveDays = $leave_days;
}

public function getLeaveDays() {
return $this->leaveDays;
}

public function setResult(string $result) {
$this->result = $result;
}

public function getResult() {
return $this->result;
}

}

interface State {
public function doWork(StateMachine $ctx);
}

abstract class StateMachine {

//持有一个状态对象
protected $state; // State
protected $businessVO = null;

abstract function doWork();

public function getBusinessVO() {
return $this->businessVO;
}

public function setBusinessVO($vo) {
$this->businessVO = $vo;
}

public function getState() {
return $this->state;
}

public function setState($state){
$this->state = $state;
}

}

//请假流程的状态接口
interface LeaveRequestState extends State
{
//这里可以扩展跟自己流程相关的处理
}

//****************************************上下文环境类********************
//处理客户端请求的上下文(相当于Context角色)
class LeaveRequesContext extends StateMachine
{

public function doWork()
{
$this->state->doWork($this);
}

}

class AuditOverState implements LeaveRequestState {

public function doWork(StateMachine $ctx) {
$vo = $ctx->getBusinessVO();

if( !($vo instanceof LeaveRequesModel)) {
throw new \Exception('状态类不对');
}

echo $vo->getUser() . ",你的请假申请己经审核结束,结果是:" . $vo->getResult() . PHP_EOL;
}

}

//项目经理审核的状态类
class ProjectManagerState implements LeaveRequestState {

private $auditOverState;
private $depState;

public function __construct() {
$this->auditOverState = new AuditOverState();
$this->depState = new DepManagerState();
}

public function doWork(StateMachine $ctx) {
$vo = $ctx->getBusinessVO();

if( !($vo instanceof LeaveRequesModel)) {
throw new \Exception('状态类不对');
}

echo "项目经理审核中,请稍候..." . PHP_EOL;
echo $vo->getUser() . ",申请从 " . $vo->getBeginDate() . "开始请假,请假 " . $vo->getLeaveDays() . " 天,请部门经理审核(1为同意,2为不同意)" . PHP_EOL;

//读取控制台输入的数据
$a = 1;
$result = ($a == 1) ? "同意" : "不同意";
$vo->setResult("项目经理审核结果:" . $result);

//根据选择的结果和条件来设置一下步
if ($a == 1)
{
if($vo->getLeaveDays() > 3)
{
//如果请假天数大于3天,而且项目经理同意了,就提交
//给部门经理。
$ctx->setState($this->depState);
$ctx->doWork(); //继续执行下一步工作

}
else
{
//请假在3天以内的,由项目经理做主,转向审核结束状态
$ctx->setState($this->auditOverState);
$ctx->doWork();
}
}
else
{
//由项目经理不同意,转向审核结束状态
$ctx->setState($this->auditOverState);
$ctx->doWork();
}
}

public function __destruct() {
$this->auditOverState = null;
$this->depState = null;
}
}

//部门经理审核的状态类
class DepManagerState implements LeaveRequestState {

private $auditOverState;

public function __construct() {
$this->auditOverState = new AuditOverState();
}

public function doWork(StateMachine $ctx) {
$vo = $ctx->getBusinessVO();

if( !($vo instanceof LeaveRequesModel)) {
throw new \Exception('状态类不对');
}

echo "部门经理审核中,请稍候..." . PHP_EOL;
echo $vo->getUser() . ",申请从 " . $vo->getBeginDate() . "开始请假,请假 " . $vo->getLeaveDays() . " 天,请部门经理审核(1为同意,2为不同意)" . PHP_EOL;

//读取控制台输入的数据 这里写成固定的
$a = 1;
$result = ($a == 1) ? "同意" : "不同意";
$vo->setResult("部门经理审核结果:" . $result);

//由项目经理审核以后,转向审核结束状态
$ctx->setState($this->auditOverState);
$ctx->doWork();
}

public function __destruct() {
$this->auditOverState = null;
}
}

//创建业务对象,并设置业务数据
$lrm = new LeaveRequesModel();
$lrm->setUser("小李");
$lrm->setBeginDate("2017-12-25");
$lrm->setLeaveDays(5);

//创建上下文对象
$ctx = new LeaveRequesContext();

//为上下文对象设置业务数据对象
$ctx->setBusinessVO($lrm);

$pms = new ProjectManagerState();
$ctx->setState($pms); //向项目经理请假

//请求上下文,让上下文开始处理工作
$ctx->doWork();

项目经理审核中,请稍候…
小李,申请从 2017-12-25开始请假,请假 5 天,请部门经理审核(1为同意,2为不同意)
部门经理审核中,请稍候…
小李,申请从 2017-12-25开始请假,请假 5 天,请部门经理审核(1为同意,2为不同意)
小李,你的请假申请己经审核结束,结果是:部门经理审核结果:同意

发表在 DesignPattern | 评论关闭

crontab精确到秒执行

#!/bin/bash
#For excuting the scripts every 3 seconds in crond.
#20100124.WXG
for((i=1;i<=20;i++));do
/home/somedir/scripts.sh 2>/dev/null &
sleep 3
done

发表在 bash | 留下评论

curl post请求


 * 创建日期:2017年12月11日 23:00:35
 ****************************************************************/

//print_r(getenv());exit;

$url = 'http://baidu.com/test.html';
$data = [
    'a' => 1,
];
$gzip = false;
$action = 'Test';

var_dump(
    httpPost($url, $data, $gzip, $action)
);

function httpPost($url, $data, $gzip, $action)
{
        $connection_timeout = 3000;
        $timeout = 5000;

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
        curl_setopt($curl, CURLOPT_USERAGENT, 'GeTui PHP/1.0');
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, $connection_timeout);
        curl_setopt($curl, CURLOPT_TIMEOUT_MS, $timeout);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        $header = array("Content-Type:text/html;charset=UTF-8");
        if ($gzip) {
                $data = gzencode($data, 9);
                array_push($header,'Accept-Encoding:gzip');
                array_push($header,'Content-Encoding:gzip');
                curl_setopt($curl, CURLOPT_ENCODING, "gzip");
        }
        if(!is_null($action))
        {
                array_push($header,"Gt-Action:".$action);
        }
        curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

        $curl_version = curl_version();

        //echo $curl_version['version_number'];exit;

        if ($curl_version['version_number'] >= 462850) {
                curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, $connection_timeout);
                curl_setopt($curl, CURLOPT_NOSIGNAL, 1);
        }

        //通过代理访问接口需要在此处配置代理
        $proxyconf = [
            'host' => '127.0.0.1',
            'port' => 3306,
        ];
        //curl_setopt($curl, CURLOPT_PROXY, $proxyConf['host']);
        //curl_setopt($curl, CURLOPT_PROXYPORT, $proxyConf['port']);

        $result = curl_exec($curl);
		$info = curl_getinfo($curl);
		$code = $info["http_code"];

        if (curl_errno($curl) != 0 && $code != 200) {
            throw new \Exception("request errno: ".curl_errno($curl).",url:".$info["url"]);
        }
        curl_close($curl);

        return $result;
}
发表在 扒拉代码 | 留下评论

查看php-fpm进程占用内存量

#求平均值
ps –no-headers -o “rss,cmd” -C php-fpm | awk ‘{ sum+=$1 } END { printf (“%d%s\n”, sum/NR/1024,”M”) }’

发表在 php-fpm | 留下评论

下载文件名中文乱码

在mac下正常,在windows下乱码

以下是响应头:

HTTP/1.1 200 OK
Server: nginx/1.10.1
Date: Tue, 05 Dec 2017 10:28:02 GMT
Content-Type: application/octet-stream; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/7.0.16
Accept-Ranges: bytes
Accept-Length: 45056
Content-Disposition: attachment; filename=教师签到表(考勤文档).doc

何解?

发表在 http | 留下评论

curl查看响应http头

wenzg@localhost:~/local/work/tengyue$ curl http://www.baidu.com -I
HTTP/1.1 200 OK
Server: bfe/1.0.8.18
Date: Tue, 05 Dec 2017 09:42:27 GMT
Content-Type: text/html
Content-Length: 277
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Connection: Keep-Alive
ETag: “575e1f60-115″
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Pragma: no-cache
Accept-Ranges: bytes

查看响应头和body
curl -v http://baidu.com

发表在 curl | 留下评论