谏知中文网

悟已往之不谏,知来者之可追

composer基本使用

发表于 2017-04-09 3010 次浏览

composer作为PHP的包管理工具,类似于Node的npm,一次引入所有的依赖包,非常方便,不会像原来,包内有多次依赖需要逐个去下载,甚至可能因为版本的关系导致代码跑不起来。

安装很简单,没有VPN的用国内镜像也不错。

//下载脚本
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
//执行安装
php composer-setup.php
//删除脚本
php -r "unlink('composer-setup.php');"

推荐全局安装,这样可以在任意位置使用composer命令了

//将文件移动到系统环境变量 PATH 所包含的路径下面
sudo mv composer.phar /usr/local/bin/composer
//修改全局配置
composer config -g repo.packagist composer https://packagist.phpcomposer.com
//查看版本
composer --version
//保持更新
composer selfupdate
//执行引入
composer install

先到github上找资源,直接将composer.json文件fork下来,执行引入

将window程序挂载到VMware下运行

发表于 2017-03-23 3380 次浏览

先用 VMware_Workstation 装个VMware(推荐 CentOS )

启动虚拟机配置 lnmp 环境(可以一键安装,具体参考:https://lnmp.org/install.html

打开 VMware 虚拟机 -> 设置 -> 选项 -> 共享文件夹(本地程序目录),其中“名称” 就是本机目录在虚拟机中的映射目录

查看 /mnt/hgfs/ 有没有映射到宿主机中的共享目录(之后我们在 Nginx 中建立站点绑定到此目录)

修改 nginx 配置,默认路径:/usr/local/nginx/conf/nginx.conf

NetBeans配置xdebug工具

发表于 2017-02-22 3439 次浏览

我用的wamp集成工具,PHP5.5.12,自带了xdebug2.2.5,先到官网下载https://xdebug.org/download.php,找到对应版本,测试了一下,我本地环境不支持2.5.0版本,所以我用的2.4.1

配置 php.ini

implicit_flush = Off
output_buffering = Off

[XDebug]
zend_extension = "f:/wamp/bin/php/php5.5.12/zend_ext/php_xdebug-2.4.1-5.5-vc11.dll"
xdebug.auto_trace = on
xdebug.remote_enable = true
xdebug.profiler_enable = on
xdebug.profiler_enable_trigger = off
;临时跟踪信息输出
xdebug.trace_output_dir     = "f:/wamp/xdebug/trace"
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "f:/wamp/tmp"
xdebug.show_local_vars = on
;开启异常跟踪
xdebug.show_exception_trace = On
;开启远程调试自动启动
xdebug.remote_autostart     = On
;收集变量
xdebug.collect_vars         = On
;收集返回值
xdebug.collect_return       = On
;收集参数
xdebug.collect_params       = On
;显示默认的错误信息
xdebug.default_enable       = On
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
;如果设得太小,函数中有递归调用自身次数太多时会报超过最大嵌套数错
xdebug.max_nesting_level    = 10000

注:wamp环境下有两个php.ini文件,都需要配置,路径:

\wamp\bin\apache\apache2.4.9\bin\php.ini

\wamp\bin\php\php5.5.12\php.ini

NetBeans安装Node插件

发表于 2017-02-06 3445 次浏览

NetBeans自带的Node插件没法用,要单独配置

https://timboudreau.com/builds/job/NetBeans-NodeJS-Plugin/lastSuccessfulBuild/

分别下载avatar.nbm和nodejs.nbm,安装

插件安装成功后,IDE->工具->选项->其他,npm和exe使用自己的路径

新建个Node项目,hello.js

var express = require('express');
var app = express();
app.get('/', function (req, res) {
console.log('abc');
res.send('hello world');
});
var server = app.listen(8001);

在IDE中,右键Run with Node,刷新http://localhost:8001/,能看到IDE有输出

Git常用命令

发表于 2017-01-16 2493 次浏览

Git下载及安装

https://git-scm.com/

初始化仓库

git init

初始化就是生成一个空的仓库,会在当前目录下生成一个.git的文件夹

添加文件

在当前目录新建一个test.txt文件

远程附件API开发(基于webuploader与layer插件)

发表于 2016-08-15 3633 次浏览

最近项目不紧,抽空写了个远程附件接口,主要为了方便以后项目中使用。考虑到兼容性和扩展性,结合使用了webuploader和layer插件,内容比较基础,有需要的朋友可自行下载,局部做些修改即可使用。需求:

1. 图片上传(单图、多图)、附件上传(使用PHP上传)

2. 水印选择功能

3. 本地删除图片同时清理服务器上资源(安全问题自行考虑)

4. 跨域问题解决(包含域名限制)

写PHP代码要注意的一些细节

发表于 2016-07-18 2276 次浏览

作为解释型语言,PHP代码的执行效率与代码结构密切相关,总结一些编码细节问题:

mt_rand()与rand()

mt_rand产生随机数的速率比用libc随机数发生器的rand快四倍

protected function randomFloat($min = 0, $max = 1) { 
                 return $min + mt_rand() / mt_getrandmax() * ($max - $min);  
 }

$this->randomFloat(1, 1.5);

protected function get_rand($length, $chars = '0123456789abcdefghijklmnopqrstuvwxyz') {
                    $hash = '';
                    $max = strlen($chars) - 1;
                    for($i=0; $i<$length; $i++) {
                              $hash .= $chars[mt_rand(0, $max)];
                     }
                     return $hash;
 }

$this->get_rand(23);

$_SERVER[REQUEST_TIME]与time()

request_time表示请求开始时的时间戳,time()通过函数返回当前Unix时间戳,要获取脚本执行时间,显然前者更高效

ckplayer、jwplayer、cuplayer播放器使用对比

发表于 2016-06-28 9225 次浏览

最近项目中有关于网页视频播放,将几种播放器的使用整理如下:

ckplayer和cuplayer都属国产播放器,能百度到详细的开发文档,学习起来非常方便

jwplayer属国外产品,相关文档较少,如果不使用翻墙工具,访问官网非常慢(https://account.jwplayer.com/sign-in?platform=1),注册账号获取key值(代码中会使用到)

对于flv/mp4视频边加载边播放、自由拖拽功能的支持:

1.ckplayer在apache、nginx、iis等主流web服务器下要单独配置、加装相关module组件等,另外需借助第三方软件yamdi给flv文件添加关键帧,借助ffmpeg给mp4文件添加关键帧、添加元数据,用qt-faststart将元数据转到视频

关于MySQL索引优化

发表于 2016-06-27 2297 次浏览

索引常用于下面操作:

1、快速查找匹配where子句的行

2、删除行

3、连表查询(大数据量表不提倡join操作)

4、对具有索引的列查找max或min值

项目中正则匹配的使用

发表于 2016-06-22 2268 次浏览
  1. 伪静态后分页格式:

function url($page, $url){
$url = explode('?',$url);
$has = preg_match('/[^\-]+\.?(?=\.)/',$url[0]); //判断url格式是否为/99-88-66.html
if($has){
$url = preg_replace('/[^\-]+\.?(?=\.)/',$page,$url[0]);
return $url;
}else{
return str_replace(urlencode('[PAGE]'), $page, $this-&gt;url); //old
}
}
echo url(4, "/show-2-876-1.html");

2.content中标签内容:

$content = $str = '[build]5.24日[/build]安卓工智能识定[build]经济可达2000亿美元[/build]';
if(preg_match_all("|\[build\](.*)\[/build\]|U", $content, wholesale jerseys china $m, PREG_PATTERN_ORDER)) {
foreach($m[1] as $key =&gt; $rt) {
$str = str_replace($m[0][$key], 'hello jync', $str);
}
echo $str;
}
hello jync安卓谷歌人工智能识定hello jync

3.content中img来源截取:

$info['content'] = '<img src="/wp-content/themes/Nana/images/random/5.jpg" />';
if(preg_match("/&lt;\s*img\s+[^&gt;]*?src\s*=\s*(\'|\")(.*?)\\1[^&gt;]*?\/?\s*&gt;/i",
$info['content'], $match)) {
$data['thumb'] = str_replace('http://img.jyncode.com/', '', $match[2]);
}
echo $data['thumb'];
/wp-content/themes/Nana/images/random/5.jpg

4.mysql replace内容替换:

update news set content = 
replace(content, 'http://www.jyncode.com/uploadfile/', '');
http://www.jyncode.com/uploadfile/1463713952761882.jpg
1463713952761882.jpg

5.regexp局部匹配: