编程(PHP)
Sep 8
window下通过composer 安装laravel5记录
how-window-composer-install-laravel5
前提:
1、已经安装composer
2、可以联网
3、安装php7

进入要安装在目录执行composer create-project laravel/laravel laravel5
记录如下

C:\Users\Administrator.LBDZ-20140426SP>cd /d F:\phpStudy\PHPTutorial\WWW                                                              F:\phpStudy\PHPTutorial\WWW>composer create-project laravel/laravel laravel5
Installing laravel/laravel (v5.7.0)
   - Installing laravel/laravel (v5.7.0): Downloading (100%)                    
Created project in laravel5                                                    
> @php -r "file_exists('.env') || copy('.env.example', '.env');"                
Loading composer repositories with package information                          
Updating dependencies (including require-dev)                                  
Package operations: 71 installs, 0 updates, 0 removals                            
- Installing vlucas/phpdotenv (v2.5.1): Downloading (100%)                      
- Installing symfony/css-selector (v4.1.4): Downloading (100%)                  
- Installing tijsverkoyen/css-to-inline-styles (2.2.1): Downloading (connectinDownloading (100%)                                      - Installing symfony/polyfill-php72 (v1.9.0): Downloading (100%)                
- Installing symfony/polyfill-mbstring (v1.9.0): Downloading (100%)            
- Installing symfony/var-dumper (v4.1.4): Downloading (100%)                    
- Installing symfony/routing (v4.1.4): Downloading (100%)                      
- Installing symfony/process (v4.1.4): Downloading (100%)                      
- Installing symfony/polyfill-ctype (v1.9.0): Downloading (100%)                
- Installing symfony/http-foundation (v4.1.4): Downloading (100%)              
- Installing symfony/event-dispatcher (v4.1.4): Downloading (100%)              - Installing psr/log (1.0.2): Downloading (100%)                                - Installing symfony/debug (v4.1.4): Downloading (100%)                         - Installing symfony/http-kernel (v4.1.4): Downloading (100%)                   - Installing symfony/finder (v4.1.4): Downloading (100%)                        - Installing symfony/console (v4.1.4): Downloading (100%)                       - Installing doctrine/lexer (v1.0.1): Downloading (100%)                        - Installing egulias/email-validator (2.1.5): Downloading (100%)                - Installing swiftmailer/swiftmailer (v6.1.2): Downloading (100%)               - Installing paragonie/random_compat (v9.99.99): Downloading (100%)             - Installing ramsey/uuid (3.8.0): Downloading (100%)                            - Installing psr/simple-cache (1.0.1): Downloading (100%)                       - Installing psr/container (1.0.0): Downloading (100%)                          - Installing symfony/translation (v4.1.4): Downloading (100%)                   - Installing nesbot/carbon (1.33.0): Downloading (100%)                         - Installing monolog/monolog (1.23.0): Downloading (100%)                       - Installing league/flysystem (1.0.46): Downloading (100%)                      - Installing erusev/parsedown (1.7.1): Downloading (100%)                       - Installing dragonmantank/cron-expression (v2.2.0): Downloading (connecting..Downloading (100%)                                                                - Installing doctrine/inflector (v1.3.0): Downloading (100%)                    - Installing laravel/framework (v5.7.2): Downloading (100%)                     - Installing fideloper/proxy (4.0.0): Downloading (100%)                        - Installing nikic/php-parser (v4.0.3): Downloading (100%)                      - Installing jakub-onderka/php-console-color (0.1): Downloading (connecting...Downloading (100%)                                                                - Installing jakub-onderka/php-console-highlighter (v0.3.2): Downloading (connDownloading (100%)                                                                - Installing dnoegel/php-xdg-base-dir (0.1): Downloading (100%)                 - Installing psy/psysh (v0.9.8): Downloading (100%)                             - Installing laravel/tinker (v1.0.7): Downloading (100%)                        - Installing beyondcode/laravel-dump-server (1.2.1): Downloading (connecting..Downloading (100%)                                                                - Installing fzaninotto/faker (v1.8.0): Downloading (100%)                      - Installing hamcrest/hamcrest-php (v2.0.0): Downloading (100%)                 - Installing mockery/mockery (1.1.0): Downloading (100%)                        - Installing filp/whoops (2.2.0): Downloading (100%)                            - Installing nunomaduro/collision (v2.0.3): Downloading (100%)                  - Installing sebastian/version (2.0.1): Downloading (100%)                      - Installing sebastian/resource-operations (1.0.0): Downloading (connecting...Downloading (100%)                                                                - Installing sebastian/object-reflector (1.1.1): Downloading (100%)             - Installing sebastian/recursion-context (3.0.0): Downloading (100%)            - Installing sebastian/object-enumerator (3.0.3): Downloading (100%)            - Installing sebastian/global-state (2.0.0): Downloading (100%)                 - Installing sebastian/exporter (3.1.0): Downloading (100%)                     - Installing sebastian/environment (3.1.0): Downloading (100%)                  - Installing sebastian/diff (3.0.1): Downloading (100%)                         - Installing sebastian/comparator (3.0.2): Downloading (100%)                   - Installing phpunit/php-timer (2.0.0): Downloading (100%)                      - Installing phpunit/php-text-template (1.2.1): Downloading (100%)              - Installing phpunit/php-file-iterator (2.0.1): Downloading (100%)              - Installing theseer/tokenizer (1.1.0): Downloading (100%)                      - Installing sebastian/code-unit-reverse-lookup (1.0.1): Downloading (connectiDownloading (100%)                                                                - Installing phpunit/php-token-stream (3.0.0): Downloading (100%)               - Installing phpunit/php-code-coverage (6.0.7): Downloading (100%)              - Installing doctrine/instantiator (1.1.0): Downloading (100%)                  - Installing webmozart/assert (1.3.0): Downloading (100%)                       - Installing phpdocumentor/reflection-common (1.0.1): Downloading (connecting.Downloading (100%)                                                                - Installing phpdocumentor/type-resolver (0.4.0): Downloading (100%)            - Installing phpdocumentor/reflection-docblock (4.3.0): Downloading (connectinDownloading (100%)                                                                - Installing phpspec/prophecy (1.8.0): Downloading (100%)                       - Installing phar-io/version (2.0.1): Downloading (100%)                        - Installing phar-io/manifest (1.0.3): Downloading (100%)                       - Installing myclabs/deep-copy (1.8.1): Downloading (100%)                      - Installing phpunit/phpunit (7.3.4): Downloading (100%)                      symfony/var-dumper suggests installing ext-intl (To show region name in time zone dump)                                                                         symfony/routing suggests installing doctrine/annotations (For using the annotation loader)                                                                      symfony/routing suggests installing symfony/config (For using the all-in-one router or any loader)                                                              symfony/routing suggests installing symfony/dependency-injection (For loading routes from a service)                                                            symfony/routing suggests installing symfony/expression-language (For using expression matching)                                                                 symfony/routing suggests installing symfony/yaml (For using the YAML loader)    symfony/event-dispatcher suggests installing symfony/dependency-injection       symfony/http-kernel suggests installing symfony/browser-kit                     symfony/http-kernel suggests installing symfony/config                          symfony/http-kernel suggests installing symfony/dependency-injection            symfony/console suggests installing symfony/lock                                egulias/email-validator suggests installing ext-intl (PHP Internationalization Libraries are required to use the SpoofChecking validation)                      swiftmailer/swiftmailer suggests installing ext-intl (Needed to support internationalized email addresses)                                                      swiftmailer/swiftmailer suggests installing true/punycode (Needed to support internationalized email addresses, if ext-intl is not installed)                   paragonie/random_compat suggests installing ext-libsodium (Provides a modern crypto API that can be used to generate random bytes.)                             ramsey/uuid suggests installing ircmaxell/random-lib (Provides RandomLib for use with the RandomLibAdapter)                                                     ramsey/uuid suggests installing ext-libsodium (Provides the PECL libsodium extension for use with the SodiumRandomGenerator)                                    ramsey/uuid suggests installing ext-uuid (Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator)                  ramsey/uuid suggests installing moontoast/math (Provides support for converting UUID to 128-bit integer (in string form).)                                      ramsey/uuid suggests installing ramsey/uuid-doctrine (Allows the use of Ramsey\Uuid\Uuid as Doctrine field type.)                                               ramsey/uuid suggests installing ramsey/uuid-console (A console application for generating UUIDs with ramsey/uuid)                                               symfony/translation suggests installing symfony/config                          symfony/translation suggests installing symfony/yaml                            monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)                                                  monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)                                                           monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))                                                     monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)                                                                  monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)                                                         monolog/monolog suggests installing mongodb/mongodb (Allow sending log messages to a MongoDB server via PHP Driver)                                             monolog/monolog suggests installing php-amqplib/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)                                    monolog/monolog suggests installing php-console/php-console (Allow sending log messages to Google Chrome)                                                       monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)                                                                     monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)                                                    monolog/monolog suggests installing sentry/sentry (Allow sending log messages to a Sentry server)                                                               league/flysystem suggests installing ext-fileinfo (Required for MimeType)       league/flysystem suggests installing ext-ftp (Allows you to use FTP server storage)                                                                             league/flysystem suggests installing league/flysystem-aws-s3-v2 (Allows you to use S3 storage with AWS SDK v2)                                                  league/flysystem suggests installing league/flysystem-aws-s3-v3 (Allows you to use S3 storage with AWS SDK v3)                                                  league/flysystem suggests installing league/flysystem-azure (Allows you to use Windows Azure Blob storage)                                                      league/flysystem suggests installing league/flysystem-cached-adapter (Flysystem adapter decorator for metadata caching)                                         league/flysystem suggests installing league/flysystem-eventable-filesystem (Allows you to use EventableFilesystem)                                              league/flysystem suggests installing league/flysystem-rackspace (Allows you to use Rackspace Cloud Files)                                                       league/flysystem suggests installing league/flysystem-sftp (Allows you to use SFTP server storage via phpseclib)                                                league/flysystem suggests installing league/flysystem-webdav (Allows you to use WebDAV storage)                                                                 league/flysystem suggests installing league/flysystem-ziparchive (Allows you to use ZipArchive adapter)                                                         league/flysystem suggests installing spatie/flysystem-dropbox (Allows you to use Dropbox storage)                                                               league/flysystem suggests installing srmklive/flysystem-dropbox-v2 (Allows you to use Dropbox storage for PHP 5 applications)                                   laravel/framework suggests installing aws/aws-sdk-php (Required to use the SQS queue driver and SES mail driver (^3.0).)                                        laravel/framework suggests installing doctrine/dbal (Required to rename columns and drop SQLite columns (^2.6).)                                                laravel/framework suggests installing ext-pcntl (Required to use all features of the queue worker.)                                                             laravel/framework suggests installing ext-posix (Required to use all features of the queue worker.)                                                             laravel/framework suggests installing guzzlehttp/guzzle (Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (^6.0).)       laravel/framework suggests installing league/flysystem-aws-s3-v3 (Required to use the Flysystem S3 driver (^1.0).)                                              laravel/framework suggests installing league/flysystem-cached-adapter (Required to use the Flysystem cache (^1.0).)                                             laravel/framework suggests installing league/flysystem-rackspace (Required to use the Flysystem Rackspace driver (^1.0).)                                       laravel/framework suggests installing league/flysystem-sftp (Required to use the Flysystem SFTP driver (^1.0).)                                                 laravel/framework suggests installing moontoast/math (Required to use ordered UUIDs (^1.1).)                                                                    laravel/framework suggests installing nexmo/client (Required to use the Nexmo transport (^1.0).)                                                                laravel/framework suggests installing pda/pheanstalk (Required to use the beanstalk queue driver (^3.0).)                                                       laravel/framework suggests installing predis/predis (Required to use the redis cache and queue drivers (^1.0).)                                                 laravel/framework suggests installing pusher/pusher-php-server (Required to use the Pusher broadcast driver (^3.0).)                                            laravel/framework suggests installing symfony/dom-crawler (Required to use most of the crawler integration testing tools (^4.1).)                               laravel/framework suggests installing symfony/psr-http-message-bridge (Required to psr7 bridging features (^1.0).)                                              psy/psysh suggests installing ext-pcntl (Enabling the PCNTL extension makes PsySH a lot happier :))                                                             psy/psysh suggests installing ext-posix (If you have PCNTL, you'll want the POSIX extension as well.)                                                           psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)                                                                         psy/psysh suggests installing hoa/console (A pure PHP readline implementation. You'll want this if your PHP install doesn't already support readline or libedit.)                                                                               filp/whoops suggests installing whoops/soap (Formats errors as SOAP responses)  sebastian/global-state suggests installing ext-uopz (*)                         phpunit/php-code-coverage suggests installing ext-xdebug (^2.6.0)               phpunit/phpunit suggests installing phpunit/php-invoker (^2.0)                  phpunit/phpunit suggests installing ext-soap (*)                                phpunit/phpunit suggests installing ext-xdebug (*)                              Writing lock file                                                               Generating optimized autoload files                                             > Illuminate\Foundation\ComposerScripts::postAutoloadDump                       > @php artisan package:discover                                                 Discovered Package: beyondcode/laravel-dump-server                              Discovered Package: fideloper/proxy                                             Discovered Package: laravel/tinker                                              Discovered Package: nesbot/carbon                                               Discovered Package: nunomaduro/collision                                        Package manifest generated successfully.                                        > @php artisan key:generate                                                     Application key [base64:4qM4I6Fxf1o/NjYtnD9Cq7l184K1RM6wws+1spuw3ws=] set successfully.                                                              F:\phpStudy\PHPTutorial\WWW>

现在通过http://localhost/laravel5/public,出现下面的内容,就表示已经初步安装完成了。                                                      





如果碰到
phpstudy2018本地配置教程You don't have permission to access解决 参考
http://itlife365.com/blog/post/phpstudy2018-no-have-permission-to-access.php

May 28
--begin by itlife365.com
PHP删除目录及目录下所有文件或删除指定文件经典代码收藏分享
  1. /**
  2.  * 删除目录及目录下所有文件或删除指定文件
  3.  * @param str $path   待删除目录路径
  4.  * @param int $delDir 是否删除目录,1或true删除目录,0或false则只删除文件保留目录(包含子目录)
  5.  * @return bool 返回删除状态
  6.  */
  7. function delDirAndFile($path, $delDir = FALSE) {
  8.     $handle = opendir($path);
  9.     if ($handle) {
  10.         while (false !== ( $item = readdir($handle) )) {
  11.             if ($item != "." && $item != "..")
  12.                 is_dir("$path/$item") ? delDirAndFile("$path/$item", $delDir) : unlink("$path/$item");
  13.         }
  14.         closedir($handle);
  15.         if ($delDir)
  16.             return rmdir($path);
  17.     }else {
  18.         if (file_exists($path)) {
  19.             return unlink($path);
  20.         } else {
  21.             return FALSE;
  22.         }
  23.     }
  24. }
  25. php dir del
  26. how-php-cascade-del-dir
--end by itlife365.com
Tags: , ,
May 28
--begin by itlife365
php的unlink()函数删除上级目录文件注意事项分享
unlink()删除目录无效吗?
新手比较容易犯的错误,unlink()函数默认的权限只在本目录及子目录,删除上级目录文件,需要改变当前位置,删除后再切换回来。 
如下示例

<?php
    $old = getcwd();  //当前目录
    chdir($path_to_file);   //切换到工作目录
    unlink($filename);   //删除文件
    chdir($old);  //切换到原目录   
?>
cause-php-unlink-supper-dir
---end by itlife365
Tags: ,
May 28

ThinkPHP3的缓存技术file分享by itlife365.com begin
如果没有缓存的网站是百万级或者千万级的访问量,会给数据库或者服务器造成很大的压力,通过缓存,大幅减少服务器和数据库的负荷。假如我们 把读取数据的过程分为三个层,第一个是访问层,第一个是缓存层,第三个是数据库存取层。如果没有缓存层,访问层是直接从数据库存取层读取数据,而设置缓存 后,访问层不再是直接在数据库存取层读取,而是从缓存层读取数据。
我们做个简单的对比,假设一个页面,在一个小时可被访问100万次,如 果这个页面每次被访问的时候,都直接读取数据库后再编译生成,在一个小时内将会重复性的生成100万次;而如果这个页面被周期性的缓存10分钟,也就是每 间隔10分钟缓存数据才会被生成一次,一个小时内只会被生成6次,两种方式一对比,效果明显,两种比较下服务器负荷的压力比差别十几万倍以上,缓存技术将 使得网站负载在高峰期游刃有余。kyrzy.com 可以让转运的网站
 
thinkphp的缓存方式有许多种,如File、Apachenote、Apc、Eaccelerator、Memcache、Shmop、Sqlite、Db、Redis和Xcache,现在我来说一下File缓存。
Thinkphp缓存文件的配置
 Home是我建立的前台项目,在Home\Conf\config.php找到缓存的配置文件,配置如下:

<?php
/**
 * 配置文件
 */
 return array(
 'DB_TYPE'=>'mysql',
 'DB_HOST'=>'127.0.0.1',
 'DB_NAME'=>'itlife365',
 'DB_USER'=>'thinphp', //自己修改
 'DB_PWD'=>'123456',
 'DB_PORT'=>'3306',
 'DB_PREFIX'=>'kyrzy_',//kyrzy.com 可以让转运
 'DATA_CACHE_TYPE'=>'file',//设置缓存方式为file
 'DATA_CACHE_TIME'=>'600',//缓存周期600秒
);
?>
thinkphp cache
控制器Thinkphp缓存函数的使用
在thinkphp中,我喜欢使用快捷缓存函数S()进行缓存; 其用法如下:
 S('data',$Data);//使用data标识缓存$Data数据
 S('data',$Data,600);// 缓存$Data数据600秒
 $Data = S('data');// 获取缓存数据
 S('data',NULL);// 删除缓存数据
 
下面是是前台项目控制器的完整代码
<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action{
    public function index(){
      //如果有缓存,则读取缓存数据
      //如果没有缓存,则读取数据库当中的数据放入缓存
      $lists=S('lists');
            if(empty($lists)){
        $news=M('news');
        $lists=$news->select();
        S('lists',$lists,600);
        echo '这是直接读取数据库的数据';
         }
      dump($list);
访问http://127.0.0.1/Home/index.php/Index/index 输出:
 
这是直接读取数据库的数据
array(10) {
[0] => array(12) {
["id"] => string(1) "1"
["catid"] => string(2) "13"
["title"] => string(4) "thinkphp的缓存技术"
["content"] => string(8) "thinkphp的缓存技术"
["tags"] => string(4) "缓存"
["thumb"] => string(0) ""
["description"] => string(7) "thinkphp的缓存技术"
["inputtime"] => string(10) "1348370202"
["posid"] => string(1) "1"
["ord"] => string(1) "2"
["hits"] => string(1) "1"
["status"] => string(1) "1"
}
...
 
说明,第一次运行时,会打印出如上面所示信息,刷新一下页面后,少了“ 这是直接读取数据库的数据",说明读取的是先前生成的缓存数据。

ThinkPHP3的缓存技术file分享by itlife365.com end

Tags: ,
May 28

使用thinkphp3.1页面默认编码GB2312,乱码,查看编码改为UTF-8,正常显示有关问题解决经验分享

今天使用thinkphp 3.1开发的时候遇到一个很奇怪的问题,页面返回乱码,需要通过浏览器点击查看->编码->改为UTF-8才能正常显示。
查看模版代码的页面head属性里面已经设置成GB2312编码,但是清空缓存重新使用浏览器默认时还是乱码,默认显示UTF-8
这个问题纠结了很久,网上说有可能是文件生成时本身的编码所致。
通过记事本或者UE重新生成文件并自动字符集编码在生成文件时就选定好UTF-8编码的,然后再将代码黏贴进去,网上说问题可以解决,但是我试了下还是不行。
后面通过F12 查看了一下,是服务器返回的时候响应表头context-type还是:text/html;charset=utf-8 ;虽然响应的正文是:
<meta http-equiv="content-type" content="text/html;charset=gb2312"> 但是最终显示处理的还是乱码。
知道问题的所在了,需要在服务端返回给客户端浏览器的时候指定编码。通过conf.php添加配置项'DEFAULT_CHARSET'=>'gbk'问题解决了
截图如下:



响应的设置

同时我的数据库前端数据库的链接配置串是'DB_CHARSET'=>'gbk'




然后发现一个问题,php 中,我的表设置的是utf-8的字符集,后台录入文字的时候conf.php的链接字符串配置的是
'DB_CHARSET'='utf8'// thinkphp的默认配置
'DEFAULT_CHARSET' 没有设置,听说默认的就是utf8
'页面的字符集设置为'<meta http-eqiv="context-type" content="text/html;charset=utf-8" 
后台页面显示正常,功能正常

前台就是不一样了。
录入文字的时候conf.php的链接字符串配置的是
'DB_CHARSET'='gbk'// thinkphp的默认配置utf8
'DEFAULT_CHARSET'='gbk' 没有设置,听说默认的就是utf8
'页面的字符集设置为'<meta http-eqiv="context-type" content="text/html;charset=gb2312" 
前台功能也正常了。不信您也访问看看:
http://kyrzy.com/article/1.html
所以感觉和数据库的表字符集设置没有关系;

我本地客户端分布建了两张表两种字符集的。都可以显示
如下
CREATE TABLE IF NOT EXISTS `ic_testgbk` (

`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 50 ) NOT NULL ,
PRIMARY KEY ( `id` )

) ENGINE = MYISAM DEFAULT CHARSET = gb2312 COMMENT = 'gb2312' AUTO_INCREMENT =2;# MySQL 返回的查询结果为空(即零行)。
--
-- 导出表中的数据 `testgbk`
--
INSERT INTO `ic_testgbk` ( `id` , `name` ) 
VALUES ( 1, '我是gb2312 的' ) ;# 影响列数: 1
-- --------------------------------------------------------
--
-- 表的结构 `testutf8`
--
CREATE TABLE IF NOT EXISTS `ic_testutf8` (

`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 50 ) NOT NULL ,
PRIMARY KEY ( `id` )

) ENGINE = MYISAM DEFAULT CHARSET = utf8 COMMENT = 'utf8' AUTO_INCREMENT =2;# MySQL 返回的查询结果为空(即零行)。
--
-- 导出表中的数据 `testutf8`
--
INSERT INTO `ic_testutf8` ( `id` , `name` ) 
VALUES ( 1, '我是UTF8 S的但是' ) ;# 影响列数: 1


可以让转运的网站 www.kyrzy.com
php gbk gb2312 utf8
--end by itlife365.com
 

Tags: , , ,
分页: 1/20 第一页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]