当前位置:网站首页>Notes on development experience: TP5 exp query, SQL analysis, JQ, applet, right-click menu, Linux skills, shell skills, mysql, etc
Notes on development experience: TP5 exp query, SQL analysis, JQ, applet, right-click menu, Linux skills, shell skills, mysql, etc
2022-06-13 08:22:00 【SDL Dahua】
Continuous updating :【 Experience is updated from time to time 】, Learning together .
utilize shell Automatic backup MySQL Specify database :
#!/bin/sh
dir=`date +%Y-%m-%d_%H:%M`
mysqldump zcc7>/home/zc/backup-${dir}.sql -urootComposer Alibaba cloud full image :
Global configuration ( recommend )
All projects will use this image address :
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
Unconfigure :
composer config -g --unset repos.packagistCentOS Check the intranet IP:
# Be careful ! No ipconfig!
ifconfig -a

mysql Slow log analysis :
// mysqldumpslow
// -t( Time ) 10(N second )
// -s( Sort ) t( Time )
// -g( Regular ) "select"( Regular matching content )
// /home/tmp/mysql/mysql_slow.log( Location of slow log file )mysqldumpslow -t 10 -s t -g "select" /home/tmp/mysql/mysql_slow.log;php var_export() function
// Used to show the variable structure
var_export($array,true);//( Commonly used for logging )
This function returns structural information about the variables passed to it , It and var_dump() similar , The difference is that the representation it returns is legal PHP Code .
You can do this by setting the second parameter of the function to
TRUE, This returns the representation of the variable .$a = var_export($array,true) Print out variables, including types, and record them Then the output , It is often used to record logs
array (
0 => 1,
1 => 2,
2 =>
array (
0 => 'a',
1 => 'b',
2 => 'c',
),
)
linux Text substitution :
Ask one by one if the first in each line boy Replace with girl
:%s/boy/girl/c
Ask one by one if all in each row boy Replace with girl:%s/boy/girl/cg
No, %: Replace the line of the cursor , Yes %: Replace all lines .No, g: Just replace the first , Yes g: Replace all .
No, c: Do not ask whether to replace , Yes c: Ask if you want to replace ( Ask as many times as you replace ) .
//linux Package files :
tar -cvf The packaged file name Files to pack ( Multiple files are separated by spaces )
for example :tar -cvf test.zip test( This is a directory , Contains a large number of files )
//linux Change file name :
mv The original document A new file
for example :mv test.txt test2222.txt
//PHP A summary of experience in judging login (tp6):
- Submit login to save session, This city will .
- Request other url, When validation is required , What do I do ? I used to implement request interception in a function controller , But the code is not good enough .
- Summary method : Create two new base controller files ,LoginController,PublicControlller, Inherit the operations that need to be logged in LoginController, Inheritance without login PublicController.
- ( Optional ) stay LoginController Add middleware to the ( I am using LoginCheck.php Middleware class , Name yourself ), Use middleware to verify login
- Verify that you are not logged in , Redirect to a that does not require login PublicControlller Medium redirect In operation , Jump to the login interface .

//grep Search for files that contain certain text :
grep 'test' d* # Show all to d The opening file contains test The line of
grep 'test' aa bb cc # Displayed in the aa,bb,cc The file contains test The line of
# for example :
grep 'error' 1616122261-19.log # Find the file that contains error Wrong key line
# Very practical
grep -C 50 'error' 1616122261-19.log # View includes error Before and after string and 50 Row content //shell Script syntax detection tool :
# Command line
# Command line installation is also very simple ( Remember to use root jurisdiction ),ubuntu Next :
$ apt-get install shellcheck
#centos Next :
$ yum -y install epel-release
#Fedora Next :
$ dnf install ShellCheck
# The method of use is also very simple :
$ shellcheck myscript.sh//linux Start and stop of task :
# stop it
systemctl stop crond.service
# start-up
systemctl start crond.service//Linux Check the system top -c Command to view memory usage
Log view command :
# see git.log Last 100 Row content
tail -n 100 git.log (n It's the number of lines )Command function :
Used to display the end of the specified file , When no file is specified , To process as input information . Often check log files .
//CURL To initiate a request, bring the request agreement
Such as :http:// and https://
// Judge whether to upload files mine type
// Upload file information
$img = $_FILES['img'];
if ($img)
{
// File storage directory , And Ben php File at the same level
$dir = dirname(__file__);
$filename = $img['name'];
$tempname = $img['tmp_name'];
$savepath = "$dir\\$filename";// Change here to the storage directory you need
$state = move_uploaded_file($tempname, $savepath);
// If the upload is successful , preview
if($state)
{
echo "<img src='$filename' alt='$filename' /> ";
}
// Get file types here start php>5.3
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $savepath);
// Get file types here end
echo $mime;
}// Verify whether the bank card number is correct and judge which bank it is
https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo=2227003766470038387&cardBinCheck=true
//MySQL Command line export data :
export web_auto_code database web_test surface >( To ) test.txt file , The file can specify a path eg: D:\sql\data\test.txt // It can be used after testing
mysqldump -u root -p web_auto_code web_test > test.txt//Ubuntu Of Linux Next scheduled task
use crontab -e Command to open task edit , as follows :
*/5 * * * * curl 'http://sss.yasndudi.com/OA/OaNotice/index' // Every time 5 Minutes to initiate a request
*/1 * * * * cd /www/web/www.ss.com;git pull // Update the code every minute
*/1 * * * * chown -R www-data:www-data /www/web/ // Delete every minute
*/1 * * * * /www/web/abc.playone.cn/task/order_warn_stask.php// Every minute PHP file
Then save and restart .
Tips :
start-up :sudo /etc/init.d/cron start close :sudo /etc/init.d/cron stop
restart :sudo /etc/init.d/cron restart service crond reload :sudo /etc/init.d/cron reload
It can be used ps aux | grep cron Command view cron Started or not //like The problem of slow query is solved ( Index required + Specify query fields explicitly )
// When there's too much data ,like It's going to be inefficient , Because it is a full table scan , No index
// The solution is as follows
Rewrite it :
In the use of like You must add an index to the field , also like When matching, you must explicitly define the field name .
legend ( Specify fields explicitly ):

legend ( No field specified ):

The following ones with strikethrough are no longer applicable .
// Utilization function :instr(' Field name ', 'abcdefg')>0 perhaps locate('abcdefg', ' Field name ')>0
// Example : select * from web_test where instr(title, 'abcd')>0
// Example : select * from web_test where locate('abcd', title)>0
Be careful :select Field name must be specified later , Otherwise, the index cannot be used !
// send msyql null Rows in front or behind
order by if(isnull(num),1,0), money desc; // there 1 stay 0 front , said null Rows always come first , If you switch positions, you'll be in the back
Test server :apache Set project alias
# setting for adminer
Alias /adminer "D:/projecs/xampp/adminer/"
<Directory "D:/projecs/xampp/adminer">
AllowOverride AuthConfig
Require all granted
Order deny,allow
Deny from all
Allow from 127.0.0.1
<Files "index.php">
SetHandler application/x-httpd-php
</Files>
</Directory>
// When to index ?
answer : Maintaining an index is costly , Weigh the advantages and disadvantages of using indexes when querying and modifying .
1、 Less data, no need to build ;
2、 Generally in where,group by,join,order by Add ;
3、 Add... To the fields with low repetition ;
// When to create a federated index ?
// answer :A The column has duplicate data ,B Column also has duplicate data , If AB The columns are queried together , When the repeatability is greatly reduced, you can use , Otherwise, a single column index is sufficient .
//HttpOnly Cookie.
This is to prevent XSS Attack to steal user cookie The most effective means of defense .Web Application settings cookie when , Its property to HttpOnly, The pages can be avoided cookie Malicious client JavaScript steal , Protect users cookie Information .
//apache Turn on file compression and exclude specified files
//* notes : Not tested yet , Self test if necessary . This scheme is only for memo
// step 1
// open apache Of "httpd.conf" file
// step 2
LoadModule deflate_module modules/mod_deflate.so// Get rid of the front # Number
// step 3
<IfModule mod_deflate.c>
# tell apache Compress the content transferred to the browser
SetOutputFilter DEFLATE
# Compression level 9
DeflateCompressionLevel 9
# The suffix is not set gif,jpg,jpeg,png The image file is compressed
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
</IfModule>
// step 4( And steps 3 A choice )
<IfModule mod_deflate.c>
# Compression level 9
DeflateCompressionLevel 9
# Compression type html、xml、php、css、js
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-javascript application/x-httpd-php
AddOutputFilter DEFLATE js css
</IfModule>//js Prevent event execution
//1 To prevent a bubble
event.stopPropagation();
//2 Block default events
event.preventDefault();
//3 return false//jq An easy way to use :siblings( Memo )
//(siblings) Always like to forget , I will never forget you when I write you down
$(obj).attr('checked', true).siblings().attr('checked', false);
// The main points of : Element must be sibling ( Brother node )// Structure small learning
// When designing the architecture , In terms of comprehensiveness, full consideration should be given to .
// It is necessary to have a strong control over the technical details in the technical selection .
// For an architect , It is very important to have a wide range of knowledge , Or it is very important to have some consideration for the future when designing .( prospect
Sex doesn't mean that we must solve the problems that may arise in the future at the beginning , Instead, we should leave behind methods that can be solved without the whole transformation , this
It is also very important for architects )
// The comprehensiveness of the design should be very good , I usually use the method of deducing the situation after the launch , Generally speaking, I will compare it in my mind
It's easy to think about these issues .
// The control of technical details is very important , At the same time, decision-making power is also very important .
// Ways to reduce mistakes : Read more 、 practice 、 How to summarize .
//Trace Importance , If you consider at the beginning , Then you can leave a good opening and lay a good foreshadowing at the beginning , It won't be too complicated to complete later .
// It should be noted that , In fact, it doesn't mean that the architect should understand everything completely , But architects should know who is reliable at some point .//Yii2 obtain web.php Configuration information
\Yii:$app->id // echo basic
\Yii:$app->bootstrap //['log, 'debug', 'gii']
// Others in the same way ......// Get database name
1、$sql = 'select database() as db;'
2、 analysis dsn// Query all field names of a table
// Query all field names of a table web_member: surface ; web_auto_code: database ;
select COLUMN_NAME,column_comment from INFORMATION_SCHEMA.Columns
where table_name='web_member' and table_schema='web_auto_code';//php Custom redirection
function redirect($url){
if (!headers_sent()) {
header("Location: ".$url);
}
}// High concurrency processing ideas ( This is to solve the problem of excessive hair 、 Process security )
1 The default value of the design field is 0 And not negative
2 to update sql That's how it's written :update test set num=num - 1
3 Once an error is reported, the client will be notified of the operation failure , Then the user can see the result
//CSS Text overflow display decimal point “...”
// There are three sentences in total
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;// Specify the browser display icon
//HTML Code
<link href="{:sysconf('browser_icon')}" rel="shortcut icon">//browser_icon: Yours icon Storage path //tp5 Experience notes : exp Inquire about
$m->where(['username'=>['exp'," = '$username' or mobile = '{$username}'"]])->find();// Senior experience , Add impairment directly to the database , Prevent dirty data in large traffic
// Experience 1
$user->save(['gems'=>['exp',' gems-'.$gems]]);
// Experience 2 - Alternative experience 1
(new Carlist)->setInc('num',$num);
// Experience 3 (TP5.1)
$sql = Db::name('web_remittanceorder')->where(['id'=>1])->fetchSql()->update(['amount'=>['exp',' amount+'.$num]]);//MySQL Determine the length of a field :
select home_page from aaa surface where char_length(trim(home_page))<10 and char_length(trim(home_page))>1;
//explain analysis sql sentence
explain select * from table where fieldname = 'name' order by id limit 20;//js cookie operation , Refer to another article 【 Research js Of cookie operation 】
var cook = document.cookie // It is the core , Build your business logic on it .//mysql View the installation path in
//Windows
show variables like "%char%";
//Linux
ps -ef|grep mysql// Transaction rollback
There has to be innoDB Engine table support 【 I have encountered the problem that rollback is impossible before , But I forgot that the table engine does not support , Now I forget , I wish to record 】
// Follow the successful payment process
Db::startTrans();
try{
(new Pay())->paySuccess($u, $order, $trade_no);
Db::commit();
$this->success(' End of mandatory supplement ');
}catch(\Exception $e){
Db::rollback();// Need to be innoDB The engine works
$this->success(' Mandatory supplement failed ,'.$e->getMessage());
}// Wechat signature
/**
* description: Wechat inquiry order signature [ Besides the foundation api It seems to be universal ]
* author:wanghua
*/
function getWxSign($param){
ksort($param);
$str = '';
foreach ($param as $key=>$val){
if(empty($val))continue;
// When verifying call return or wechat active notification signature , The transfer of sign Parameter does not participate in signing , Compare the generated signature with the sign Value for verification
if($key == 'sign')continue;
$str.= '&'.$key.'='.$val;
}
$stringSignTemp = substr($str,1).'&key='.config('api_key');
$sign = strtoupper(md5($stringSignTemp));
return $sign;
}
/**
* description: Wechat conventional signature algorithm [ This seems to have only the foundation api It works , for example : Get... Before sharing options The signature required is it ]
* author:wanghua
*/
function getSignature($param){
if(!$param || !is_array($param))return false;
if(false !== strpos($param['url'], '#')){
$exp = explode('#', $param['url']);
if($param['url'])$param['url'] = $exp[0];
}
ksort($param);
$string1 = '';
foreach ($param as $k=>$v){
$string1.= $k.'='.$v.'&';
}
$string1 = substr($string1, 0, strlen($string1)-1);
$signature = sha1($string1);
return $signature;
}//jQuery Get separately json Object's key and val, Less use scenarios , Make a note of
// Value example :
{
"id":33,"title":"\u4f1a\u5458\u7ba1\u7406","controller":"Member",
"dbname":"member","is_deleted":0
}
$.each(d, function (k) {
console.log(k+':'+d[k]);
});// Disk space detection
function check_disk_free_space(){
if(function_exists('disk_free_space')) {
return floor(disk_free_space(INSTALL_APP_PATH) / (1024*1024));
}else{
return false;
}
}
//js( Applet ) Two dimensional array ( object ) Sort ( After testing : Small programs can also be used ), Here is the descending order
//js Two dimensional array ( object ) Sort ( After testing : Small programs can also be used ), Here is the descending order
arrArrToSort: function(data,t){
var d = [];
// Descending
if(t){
for (var i=data.length-1; i>=0; i--){
d.push(data[i]);
}
}
return d;
}// str_pad PHP Fill string length , Left 、 Right 、 Both sides
$str = "Hello World";
echo str_pad($str,30,".");//vi The revocation order of Counter cancellation
( tip : This command should be executed in the text command line state , Cannot execute... In text editing state )
'u' : Undo the last edit operation
'ctrl + r' : recovery , That is, back to the previous command
'U' : Please cancel , Undo all operations on the previous edit line
//TCP And UDP
TCP--- Transmission control protocol , It provides connection oriented 、 Reliable byte stream service . Before the client and server exchange data with each other ,
We must first establish a TCP Connect , Then we can transfer the data .TCP Provide overtime resend , Discard duplicate data , check
Validation data , Flow control and other functions , Make sure the data can be transferred from one end to the other .
UDP--- User datagram protocol , Is a simple datagram oriented transport layer protocol .UDP No reliability , It just puts
The application is passed to IP The datagram of the layer is sent out , But there is no guarantee that they will reach their destination . because UDP Transmitting data
There is no need to establish a connection between the client and the server before reporting , And there is no mechanism such as overtime retransmission , So the transmission speed is very fast .
use TCP still UDP, It depends on what your program focuses on ? Reliable or fast ?// test input="datetime-local"
//input type = datetime-local
$str = '2018-10-24T00:00';// Input
var_dump($str);
$time = strtotime($str);// Turn to time stamp Output :1540310400
var_dump($time);
var_dump(date('Y-m-d H:i:s', $time));// Convert to time format Output :2016-05-01 12:12:012:01//PHP htmlspecialchars() & htmlspecialchars_decode function
//htmlspecialchars: Put the predefined HTML Entity '<'( Less than ) and '>'( Greater than ) Convert to character
//htmlspecialchars_decode: conversely //JS Release the browser to prohibit the left and right key selection and pop-up menu
// Allow and disable left clicking , There are two ways ( practical )
// One : css Method
// Core attributes
user-seletct: none;
-webkit-user-seletct: none;
-moz-user-seletct: none;
-ms-user-seletct: none;
//none: Cannot select content
//text: Can select content
//user-seletct And all attribute : Can select content ( When all content as a whole can be selected .
// If you double-click or click a child element in the context , Then the selected part will be the highest ancestor element backtracked upward with the child element )
// Test examples - Allow selection :$('body').append('<style>*{user-seletct: all;-webkit-user-seletct: text;}</style>');
// Two :js Method
document.body.onselectstart = function(){return false;}//true Allow left click to select
document.onselectstart = new Function("event.returnValue=true;");//true Allow left click to select
// return false, You can't select
// return true, Can select
// Allow and disable pop-up context menu
document.oncontextmenu = function(){return true};//false prohibit ; true allow
// Test found , It may be in a certain line , Or a certain element has style control , Nor can it be selected ,
// Even if the above methods have been tried , The solution is , Put the... On this element class Delete or css Delete and try again ,
// This requires a certain level of skill and patience .^ ^`//MySQL String substitution
update `news` set `content`=replace(`content`,' ','');// hold content Replace the blank space in the field // To be continued TODO.....
~
边栏推荐
- The method of SolidWorks modifying text font in engineering drawing
- 有什么好的管理软件来解决茶叶批发商面临的难题
- Homestead environment setup
- Daffodil upgrade (self idempotent)
- LeetCode-按奇偶排序数组
- 实践出真知--你的字节对齐和堆栈认知可能是错误的
- Phpexcel 10008 error resolution
- Do not update the sub component page of parameter object passed from parent to child of nailing applet?
- Edge浏览器如何安装BdTab(BD)新标签页插件(图文教程)
- Sizeof, strlen find character length
猜你喜欢

使用kvm创建三台能通局域网的虚拟机

MySQL queries difference sets (missing data) by linking tables based on an associated field

array_ Pop error: only variables should be passed by reference

How to download and install stm32cubemx

汽配行业面临的难题用什么软件帮忙解决呢

Is there any good management software to solve the problems faced by tea wholesalers

Altium Designer中导入和导出设置的方法

母婴用品批发行业使用管理软件提高效率 实现降本增效

ERP basic data Kingdee

Microservice project construction III: automatic code generation
随机推荐
Leetcode- sort arrays by parity
Give code vitality -- the way to read code neatly
Local shooting range 2- file upload vulnerability (III) - Network Security
How to modify desktop path in win10 system
SQL injection experiment
sizeof、strlen求字符长度
1. fabric2.2 comprehensive learning - Preface
How app inventor accesses resource files in assets directory
How about a well-known food material distribution information management system?
File upload question type
名次的确定
判断一个字符串是否由另外一个字符串旋转而来
Did decentralized digital identity
Shell脚本常用开发规范
Common shell script development specifications
PHP PNG to webp
JS to download files in batches
Dest0g3 520 orientation
How to use annotations in word
星巴克创始人:出于安全考量 或不再向非店内消费者开放“公厕”