php 中的Etag
<?php
$str = "Barret Lee";
$Etag = md5($str);
if(array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER) and $_SERVER['HTTP_IF_NONE_MATCH'] == $Etag){
header("HTTP/1.1 304 Not Modified");
exit();
} else {
header("Etag:" . $Etag);
echo $str;
}
?>
关闭http链接
header("content-length:" . $size);
header("Connection: Close");
正则中文截断乱码
$value['content'] = preg_replace("/([\n\t\s\r]| )*/u", "", $value['content']);
url 下载文件
function downfile(){
$fileurl = $_GET['file'];
$filePath=__DIR__."/template/app/dati/file/" .$fileurl;
$fileName=$fileurl;
$file = fopen($filePath, "r"); // 打开文件 // 输入文件标签
if ($file) {
Header("Content-type:application/pdf");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . filesize($filePath));
Header("Content-Disposition: attachment; filename=" . $fileName); // 输出文件内容
echo fread($file, filesize($filePath));
fclose($file);
}
}
composer
phar
php D:/phpbox/php/composer.phar install
代理
composer config -g repo.packagist composer https://packagist.laravel-china.org
yii2 需要
composer global require "fxp/composer-asset-plugin:~1.4"
composer global require fxp/composer-asset-plugin
require 开发版本
composer require shark/simple_html_dom:dev-master
mysql测试连接
private function testMysql()
{
$sh = "timeout 2s /usr/local/mysql/bin/mysqladmin -h {$this->mysql_adress} -P {$this->mysql_port} -u{$this->mysql_name} -p{$this->mysql_pwd} ping 2>&1";
$res = exec($sh);
if (!(strpos($res,'mysqld is alive') !== false)) {
$this->addErrors(['mysql数据库连接错误!']);
}
try {
// var_dump([$this->mysql_adress .":". $this->mysql_port, $this->mysql_name, $this->mysql_pwd, $this->mysql_db_name]);die;
$dsn = "mysql:dbname={$this->mysql_db_name};host={$this->mysql_adress}:{$this->mysql_port}";
$user = $this->mysql_name;
$password = $this->mysql_pwd;
$dbh = new PDO($dsn, $user, $password);
} catch (Exception $e) {
$this->addErrors(['数据库连接不正确!']);
}
}
yii
yii post
public $enableCsrfValidation = false;
yii 分页
$queryData = new CActiveDataProvider((new OrderExt), array(
'criteria' => $query,
'pagination' => [ // 'pageSize'=>2
'pageSize'=> 20,
// 分页页码
"pageVar" => 'page',
// 设置 分页准确性
"validateCurrentPage" => false,
],
));
数据库迁移
php yiic migrate create create_edit_active_order_count_base
php yiic migrate up
public function safeUp()
{
$tableName = 'goods';
$this->addColumn($tableName, 'order_count_base', "int(10) NOT NULL DEFAULT '0' COMMENT '报名人数基数'");
$this->refreshTableSchema($tableName);
}
后台添加验证
['shop_wap,check_start_time,check_end_time','validateCheckShop'],
function validateCheckShop($attribute,$params=array()){
if ($this->apply_way == 2 && empty($this->$attribute)) {
$this->addError($attribute,$this->getAttributeLabel($attribute).'必填!');
}
}
yii1 多对多
// CategorizeLable 类名称
public function relations()
{
return array(
'cateLable' => array(self::MANY_MANY, 'CategorizeLable',
'customer_lable_map(customer_id, lable_id)'),
);
}
xdebug
zend_extension=php_xdebug.dll
xdebug.remote_enable = on
xdebug.remote_autostart=on
xdebug.remote_host = "localhost"
xdebug.remote_port = 9000
xdebug.remote_handler = "dbgp"
便捷查询
public function scopes()
{
return [
'nor' => [
'condition' => 't.deleted = 1 and t.status=1 and categorize.deleted and categorize.status=1',
],
];
}
php函数整理
curl
public static function curl_get($url, array $params = array(), $arr_header = [], $method = "GET", $timeout = 50000)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
if (!empty($arr_header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr_header);
}
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if (!empty($params)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//若给定url自动跳转到新的url,有了下面参数可自动获取新url内容:302跳转
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//设置cURL允许执行的最长秒数。
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0');
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$content = curl_exec($ch);
//获取请求返回码,请求成功返回200
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//获取一个cURL连接资源句柄的信息。
//$headers 中包含跳转的url路径
$headers = curl_getinfo($ch);
return $content;
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// $file_contents = curl_exec($ch);
// curl_close($ch);
// return $file_contents;
}
fpm 重启
- ps aux | grep php-fpm |grep master
- kill -USR2 xxx