PHP

浏览模式: 标准 | 列表 | 图文
Yii2使用自定义jQuery

Yii2使用自定义jQuery

Yii2自带的jQuery随着版本一次次的更新,其实也都在每次调整,但事实上为了兼容旧版,我们有时候不需要这么新的jquery.js,这时候,怎么办?其实只要用assetManager对jqueryAsset进行一个覆写就行了。

比如这样:
'assetManager'=>[
'bundles' => [
'yii\web\JqueryAsset' => [
'sourcePath' => null,
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => [
'js/jquery.js',
]
],
],
]
是不是很简单?
composer初装需要执行的几个命令

composer初装需要执行的几个命令

注:以下技巧在composer2下面已经没必要了。!!!!!

升级成composer2吧,全解决了

-------------

因为我一直用Yii2框架。所以安装composer和安装后需要执行的命令如下,【纯记录】

1、下载composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
#php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
2、mv composer.phar /usr/local/bin/composer #移到系统目录,变成全局命令
3、composer config -g repo.packagist composer https://packagist.phpcomposer.com #国内源
phpcomposer好象垮了!
更新为:composer config -g repo.packagist composer https://packagist.laravel-china.org
4、composer global require hirak/prestissimo #多线程
5、composer global require "fxp/composer-asset-plugin:^1.4" #升级为1.4
6、composer update -vvv
就这样了
合并后的命令
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
composer config -g repo.packagist composer https://packagist.phpcomposer.com
composer global require hirak/prestissimo
composer global require "fxp/composer-asset-plugin:^1.4"
composer update -vvv
#over
如果采用了git,记得在运行完clone后:git config credential.helper store ,可以将当前用户名和密码存下来(针对HTTP方式,如果是ssh本来就不需要)
simplepie解析爱范儿的RSS出错

simplepie解析爱范儿的RSS出错

用Simplepie解析爱范的源时,出现如下错误:http://www.ifanr.com/feed is invalid XML, likely due to invalid characters. XML error: Invalid character at line 604, column 37,比较麻烦。

最后在Simplepie的代码的1397行里加入:
$this->raw_data = preg_replace('/[^\P{C}\n]+/u','',$this->raw_data);
说实在的,这种不可见的字符最TMD恶心了!~
Yii2 PJAX的URL,微信签名错误

Yii2 PJAX的URL,微信签名错误

因为用了pjax,所以URL在请求的时候都是被自动加了?pjax-container=xxxxx,但请求完pjax后,location的pushState又会去掉这个pjax-container。所以要解决签名问题,其实就是在签名的时候把pjax-container去掉

因此jssdk()->config(xxx)的时候,先在前面加入jssdk()->setUrl(Url::to([''],true))->config('')...问题解决!

就是这么简单!

redis 127.0.0.1和localhost的性能区别

redis 127.0.0.1和localhost的性能区别

不多说上图

[2017-10-13 08:52:28]{"router":"site/test","process_time":1.05578303337,"include_files":110}
[2017-10-13 08:52:29]{"router":"site/test","process_time":1.65018391609,"include_files":110}
[2017-10-13 08:52:30]{"router":"site/test","process_time":2.24326276779,"include_files":110}
[2017-10-13 08:52:31]{"router":"site/test","process_time":2.83484601974,"include_files":110}
[2017-10-13 08:52:32]{"router":"site/test","process_time":3.45267605782,"include_files":110}
[2017-10-13 08:52:43]{"router":"site/test","process_time":0.045606136322,"include_files":110}
[2017-10-13 08:52:43]{"router":"site/test","process_time":0.0466020107269,"include_files":110}
[2017-10-13 08:52:44]{"router":"site/test","process_time":0.0419600009918,"include_files":110}
[2017-10-13 08:52:44]{"router":"site/test","process_time":0.0458340644836,"include_files":110}
[2017-10-13 08:52:44]{"router":"site/test","process_time":0.0436880588531,"include_files":110}
因为在框架里面,所以include_files就这么多(没办法,没开始opcache)
前5条是用的localhost后5条是127.0.0.1,瞅瞅,就是这样的区别!
composer 加速插件

composer 加速插件

先说再写:

composer global require hirak/prestissimo

即使你用了这玩意,还是得先用国内的源,否则所谓的加速也是白搭。
GITHUB在这里:https://github.com/hirak/prestissimo
看官网的介绍,提升有10倍,虽然 我们在国内没有这么高的提速,但感觉上还是快了不少(应该不是安慰剂)
mysql 函数与 pdo函数的对比及使用

mysql 函数与 pdo函数的对比及使用

mysql在升到php7后,原有的mysql_*函数都没有了,如果要迁移,可以参考 这一篇:https://stackoverflow.com/questions/36073703/mysql-to-pdo-comparison-table

介绍的比较详细,比如mysql常用的几个函数的转换写法,这里都有了:
随便截一点内容,详细的还是去网站看:

MySQL_ Original Driver to PDO Comparative Table

Introduction:

This table is not intended to be a tutorial or a guide to PDO, but to provide a correspondence between MySQL_ and PDO. So, some important PDO commands are missing, if they don't have a MySQL_ correspondence.

Among these omitted commands, there is a major PDO feature, the prepared statements. I strongly recommend to use it, also if only cited in this guide.

This is a very extended answer. I'm sorry for the low quality of spelling (I'm not english) and for the typos. I will try to correct and improve it in the next few days. Any suggestion or contribution is welcome.

Naming Conventions:

To avoid misunderstanding, in this answer I use:

In PDO, we have two major object types, the PDOObject (the connection between PHP and a database server) and the PDOStatement (a prepared statement and, after the statement is executed, an associated result set). In this answer, variable names are:

  • $dbh, refer to PDOobject;
  • $stmt, refer to PDOStatement.
也许你们看不出,但本博客确实升到了PHP7了

也许你们看不出,但本博客确实升到了PHP7了

如题,由于切换服务器从linode到香港,顺手将PHP升到了7。

由于之前在做好了准备工作,【[2017-01-04] - sablog for PHP7】所以迁移还是相对比较简单。
不过还是漏了一点点东西,比如
1、sablog里的split函数,看了一下他的内容,不复杂,就直接改成Explode了,没有用preg_split
2、漏网一个eregi函数,在database.php中,用preg_match('//i'),来代替了(这是官方手册上说的:http://php.net/manual/en/function.eregi.php,因为从PHP7开始就被Remove掉了,没办法)
3、一个漏网之鱼:mysql_get_server_info,其实db函数中已经有这个db::versions()方法了,但。。。他还是在代码里写了,所以调用了一下$DB->version();
目前几乎没有看到什么大问题,在include/common.php中用error_reporting(7),阻挡了大部分的warning。先混过去。如果再遇到问题就改一下

yii2终于有自己的队列了!!!

当然 ,之前yii2有一个queue,这个queu简单到只有一个run/job,其他都没有。这回终于来一个完善的了。说实话,有时候用laravel,就是因为想用他的queue。现在终于不用纠结了!

再细看一下他的composer.json。。。还是逃不脱SF的大坑!不过总算是有队列了,管它呢。这年头,所有框架最后都会被SF大一统么?

先到这里看一下教程:https://github.com/yiisoft/yii2-queue/blob/master/docs/guide/README.md

然后再回到:https://github.com/yiisoft/yii2-queue ,下载代码吧,真正使用也简单,php composer.phar require --prefer-dist yiisoft/yii2-queue,就完事了!

不过这个玩意,估计在windows下面是无效的,常用方法有:

// Push a job into queue and get massage ID.
$id = Yii::$app->queue->push(new SomeJob());

// The job is waiting for execute.
Yii::$app->queue->isWaiting($id);

// Worker gets the job from queue, and executing it.
Yii::$app->queue->isReserved($id);

// Worker has executed the job.
Yii::$app->queue->isDone($id);

估计以后的项目,默认就直接引用:yiisoft/yii2 , yiisoft/yii2-queue了!

d9095cd04c8b40b3a774b25630bcac39

推荐阅读:PHP

推荐阅读:PHP

看这里: https://blog.jetbrains.com/phpstorm/2017/06/php-annotated-monthly-june-2017/

其实在blog.jetbrains.com/phpstorm上,有很多PHP的使用方法和IDE的奇技淫巧。比如教你怎么远程debug之类的
我先贴点原文中的链接。如果要看更多,可以点击上面的链接

PHP 7.2 will have some great new features, keep your eye on this blog for a roundup once I’ve had a chance to look at the alpha in the coming weeks.

Other good posts on PHP and general development this month:

Frameworks and Libraries

We’ve got the usual slew of Laravel and Zend Framework posts, along with some interesting posts for WordPress, Yii and some more useful articles on Composer and Packagist.

Yii

Laravel

Zend Framework

Symfony

Other

Community, Career, and Events

There was an interesting interview with Taylor Otwell, creator and lead developer of Laravel tells us why Taylor Otwell Wants You To Build Your PHP Apps On Laravel. I also enjoyed an interview with Anna Filina On PHP Trainings And Future Of PHP Frameworks.

An interesting question is posed in Can 9-to-5 Developers Be Good Developers? While I disagree vehemently with some of the points made in the article, it makes for an interesting discussion.

This month I’ll be at PHP South Coast in Portsmouth this week, and DPC in Amsterdam at the end of the month. Make sure you come and say “Hi!” if you see me at any events.

好东西实在太多。。。