我对Laravel ThinkPHP Yii symfony2 CI cakephp 的看法
这是我的真心体会,在尝试使用Laravel、ThinkPHP、Yii、symfony2、CI、cakephp、Yii2 之后的真实想法(default7#zbphp.com)。
1)ThinkPHP (版本3.1.3)
我一开始用到的是ThinkPHP 3.1.3,入门门槛就是网址与方法对应这一点。当初我接触ThinkPHP3.1.3的时候其实3.2版本刚出不久,3.2与3.1.x相比是部分重构,用上了最新的命名空间,考虑到购买的虚拟主机可能不支持命名空间(命名空间必须PHP 5.3.3+才支持),也考虑到国内大部分企业如果已经用上了ThinkPHP,肯定也可能不是最新版的,所以一开始选择的是ThinkPHP3.1.3,用他做了一个网站。总体感觉很好用,他为你做了尽可能及的一切。而且thinkphp是一家公司在支持,这样就不会说突然倒闭解散,如果是企业想用PHP来做一个平台的话,很不错的选择,长期稳定。
2)Yii (版本 Yii 1.1.14)
我学会了ThinkPHP之后,我就想到了再多学一门框架吧,这样以后找工作也更好一点,谈也好谈。然后偶然一次我去一家金融方面的公司面试PHP,他们用的是Yii。回来后网上搜索了Yii相关资料,看到很多人对Yii的介绍称赞,AR、延迟加载、DAO、L10N、I18N,感觉yii一定很有前景。便开始研究Yii(Yii 1.1.x)。看手册,全英文的,偶然有看到帖子说Yii作者是中国人。后来才确认Yii 确实只中国人写的。看了入门,自己下载下来安装,感觉以自己现在的水平来说很难,很多要记忆的zii widgets,而且耦合度非常高,(我刚开始接触Yii的时候写的一个看法 http://bbs.csdn.net/topics/390807796)Html模板里面的写法耦合度更高,便放弃了。
3)cakephp (版本 2.5.1)
到了这个时候,心里想的是就选一门容易点的框架来说,想到了很多年以前就听过的那一款框架CakePHP(最新版本cakephp 2.5.1)。下载下来安装,看文档不支持命名空间、不用PHP最新的功能方法。看了英文的一部分文档,很方便的感觉,对比yii,跟thinkphp一样有专门讲到图片验证码、SESSION、cookie操作,很类似thinkphp,很多都为你做好了。然后我下载来做自己的一个网站,我一开始就先做管理员部分,结果就发现,按照cakephp 的思路,管理员和前台其实应该是在一个文件里面的。比如你有一个Post表,那么你的管理员和前台的针对Post的操作全部都是在PostController里面,而我期待的是必须前后台分离,没有耦合。
4)symfony2(symfony 2.5)
如果不是一本书上介绍到symfony,并且对他有很多非常好的评价,我想我绝对特不会知道并关注symfony2的。开始接触symfony2,发现他安装方法跟我以前接触到的PHP完全不一样,composer安装,很新颖,这完全颠覆了我以前对PHP的某些认识。Symfony2必须在PHP 5.3.3以上的版本,其实现在再去看,是必须PHP 5.4+以上版本,因为他里面的一些组件component要求的是最新版本,因为我写这篇文章的时候,我对这些框架的接触都是在数个礼拜之前,而这一段时间看的框架太多,可能有点混淆,如果有纰漏,或者探讨可以发邮件 default7#zbphp.com。安装好了symfony2之后,仔细阅读symfony2的内容,他最大的特点就是将一整套程序的运行对比成电脑计算机的Input+Output+CPU。Request Resonse 和 PHP处理部分(其实这样的思路后来其他的框架Yii laravel cakephp 3.x全都借鉴了)。我再继续阅读symfony2的文档,他里面不会像thinkphp那样讲图片验证码、IP、IP归属地怎么查询、图片怎么上传处理之类的,搜索很多相关资料,感觉symfony2是一个HTTP框架,但是并不是MVC框架,而是一个HTTP框架。他有C 和V,但是没有M。思路跟yii thinkphp完全不一样的,组件化component的思想,跟Ror的任何都是对象的思路不一样,他是任何都是组件,低耦合。
5)Laravel (Laravel4.2)
我继续搜索PHP MVC Framework方面的帖子,找了很久,看到有一篇文章上配了一张图(上面那一张),说截止到2013年年底,Laravel占有率是最高的!然后便去了解laravel,百度搜索Laravel,已经有蛮多网站了,比如 www.golaravel.com,介绍laravel框架,文档,介绍到Restful功能、是企业级框架。
其实我一直以来都想找一个这样的框架,长期、稳定,不会一下子就解散了不支持了,不会说今天一变明天一变。并且有命名空间最新的几个功能得有,可以省去以后经常重构麻烦。下载安装laravel,也是composer方式安装。然后开始用了,发现他官方上一直很推崇的路由功能,使用起来却很繁琐。每一条请求网址都要写一条路由。想到这里觉得不敢想像,一个网站的网址很多的,而且不相同的规律,包括管理员后台,如果这样每一条网址都要写一个路由,而且全部都是些到routes.php这一个文件里面去,你想象一下,加载要耗费多少资源时间???而且描述上说的文档丰富,但是看到了真的很少,不齐全(对比symfony cakephp,他的文档真少)。
6)重新回到Yii(Yii 2.0)
其实我这一阵子一直都在寻找一款MVC框架,支持命名空间、支持AR、方便好用,有图片验证码自动生成、图片上传处理,水印处理,支持I18N,多语言、有很多人在使用、成熟的文档、稳定长期、适合企业级。最后对比了这么多框架还是回到了最开始想到的那几个框架,重新回到Yii。想到自己为什么一开始就觉得Yii不适合,但去对比了其他框架,才发现Yii是几乎最好的,追求的是执行效率、速度(当然相对)。
对比了这么多框架,发现一个现象,中国的程序和国外的程序员的思维不同点,中国的程序员是看钱包点菜,外国的程序员完全是看自己喜好来点菜。用另外一种说法来讲,中国的程序员是努力去适应环境,而国外的程序员是努力改变环境。怎么来说,同样一个需求项目,中国程序员首先考虑到的是服务器支持吗?版本支持吗?承受得了多少访问?配置方面的限制怎么样,怎么样运行最快,国内90%以上的PHP程序都是运行在虚拟主机上,一台服务器数百个甚至数千个网站。而国外的程序员完全不需要考虑这些,他们按照自己的思路来,完全不考虑配置,他应该觉得怎么样一个架构思路,而不用去关心机器怎么样运行最快,人来决定架构,而不是机器配置决定架构,有种很文艺的感觉。
比如Laravel,他里面每一个网址就必须写一个路由,这完全是不考虑服务器性能,假设整个网站有3000不同形式的个网址,那一次性加载得多少耗费??还有国外比较流行的程序Drupal,也是完全不计较服务器的配置,而是单纯从人的思考的角度去规划的,他将所有的内容全都想象成节点,key-val的形式,彻底忽略配置的限制。我在本地机子(双核CPU 6G内存)的电脑上运行drupal都卡得无法形容,更别提上传到服务器。(文 bydefault7#zbphp.com)

Effective methods to prevent session fixed attacks include: 1. Regenerate the session ID after the user logs in; 2. Use a secure session ID generation algorithm; 3. Implement the session timeout mechanism; 4. Encrypt session data using HTTPS. These measures can ensure that the application is indestructible when facing session fixed attacks.

Implementing session-free authentication can be achieved by using JSONWebTokens (JWT), a token-based authentication system where all necessary information is stored in the token without server-side session storage. 1) Use JWT to generate and verify tokens, 2) Ensure that HTTPS is used to prevent tokens from being intercepted, 3) Securely store tokens on the client side, 4) Verify tokens on the server side to prevent tampering, 5) Implement token revocation mechanisms, such as using short-term access tokens and long-term refresh tokens.

The security risks of PHP sessions mainly include session hijacking, session fixation, session prediction and session poisoning. 1. Session hijacking can be prevented by using HTTPS and protecting cookies. 2. Session fixation can be avoided by regenerating the session ID before the user logs in. 3. Session prediction needs to ensure the randomness and unpredictability of session IDs. 4. Session poisoning can be prevented by verifying and filtering session data.

To destroy a PHP session, you need to start the session first, then clear the data and destroy the session file. 1. Use session_start() to start the session. 2. Use session_unset() to clear the session data. 3. Finally, use session_destroy() to destroy the session file to ensure data security and resource release.

How to change the default session saving path of PHP? It can be achieved through the following steps: use session_save_path('/var/www/sessions');session_start(); in PHP scripts to set the session saving path. Set session.save_path="/var/www/sessions" in the php.ini file to change the session saving path globally. Use Memcached or Redis to store session data, such as ini_set('session.save_handler','memcached'); ini_set(

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
