Home > Article > Backend Development > The ideas and methods for newbies to learn PHP are reprinted from Zhihu
作者:沈杰
链接:https://www.zhihu.com/question/20003635/answer/81745609
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
因为这是面试中会问到的一个问题,虽然它看起来很简单。
回答做网站的,也就是个简单建站的水平。
回答做网站后端开发的,对PHP有了一定的认识。
回答做后端处理的,有了更深层次的认识。
学习一样技能,你得先清楚这项技能是到底做什么的,说到这里,我想大家都会简单的说是做网站的,因为PHP在WEB领域应用最为广泛,大多数网站都是用PHP做的。准确的说PHP是做网站的后端开发的,其实我这样说还不算正确,PHP只是做后端开发的,但不只是网站而已。就像现在比较火的APP开发也可以用PHP做后端处理。
PHP相对于其他语言,比较简单,相对好上手,比较适合零基础的人学习,但是就像我上面说的那样,PHP只完成了一个网站或者系统的一部分。
一个运行的网站或者软件系统可以分为前端页面,后端程序,数据库,linux。而处理后端的PHP仅仅是只占了四分之一,PHP本身的东西其实并不多,真正多的东西都在PHP之外,所以单纯的掌握PHP并不足已做出什么产品,可能连工作都找不到。
关于学习PHP,我想讲讲我的心路历程:
前端:
但凡是一个网站都必须得让人能看得见,使用得起来。任何一个网站可以没有数据库,可以没有后端程序,但是必须得有前端页面,而这也是最早期的网站形态—一 一个只能展示文字和图片等信息的静态页面。
掌握静态网页的制作技术是学习开发网站的先决条件。这里面的学习包括 HTML,css,javascript,它们可以直接使用浏览器运行。
HTML负责网页的结构,用它来规定网页排版中哪部分是文字,哪部分可以放图片,音频文件,视频文件放在网页中什么位置显示等。
CSS可以把这些文字,图片,视频等信息拥有一定的合理好看的样式,可以定义文字的大小,颜色,图片的大小等等。
javascript可以让网页与人产生交互,就像你登录网站,点击登录按钮就会跳转,把鼠标放到菜单,菜单就会自动展示下拉,逛淘宝时,把鼠标放在产品图片上,图片就会放大等等。
我的学习技巧和心得:
我算是零基础学习开发的吧,连大学都没上,没系统的学过计算机专业,初次开始学习html时,我是以w3c手册为学习教材,但是越往后看越觉得里面写的东西琐碎繁多,手册里介绍了很多标签,标签又有很多属性,它们各自又代表的什么含义。
就像下面的这个表示表格的一些标签,这是手册给出的概念,看了之后似乎也明白又不太明白,看完又没记住,回想起来,还是一头雾水,像是什么也没学到。
<img src="https://pic2.zhimg.com/50/c96d67c8eb82d138cb21a610472523a9_hd.png" data-rawwidth="636" data-rawheight="377" class="origin_image zh-lightbox-thumb" width="636" data-original="https://pic2.zhimg.com/c96d67c8eb82d138cb21a610472523a9_r.png">
那时我开始心急了,我无法想象我居然连基础的东西都都学不会,思量了一两天,我觉得我还是太浮躁了,我决定重新开始,动手敲敲试试,以前只是光看。就这样开始后,仿照别人家写的,运行一下看看浏览器显示的是什么效果,去掉某个属性之后看看是什么反应。我就这样笨拙的进行着,把每一个标签,每一个属性都敲了一遍,一个个的看到效果之后,我才理解手册里描述的概念是怎么回事了。
前端的知识比较锁碎,没有太多逻辑性可言。其中html和css的任何元素标记都要亲自动手实践,大部分新手之所以觉得难学,看不懂手册概念,主要是学习方法不对,“懒”是首要原因,因为不动手实践,光看概念是没什么用的。
所以克服掉懒的习惯,动起手来写一个HTML标记,运行之后看看效果吧,这样你才能真正掌握住。
不过,我建议初学的同学还是先看视频为好,因为操作效果都能看的到,手册这东西作为工具使用。
关于html和css中的标签和属性你没必要完全一个不差的记住,因为这没有太大的意义,等你做了一个小项目之后,你只需要记住常用的就行,其他的做到有印象,用的时候能想到,然后查手册即可。
当你学完之后一定要做一个简单的小项目,你学习时针对的都是散乱的知识点,最后要把这些东西整体的用一遍。
以下这个图就是我上一年学习html最后自己动手做的一个小页面:
<img src="https://pic4.zhimg.com/50/1afe7af6dfbc15a89d37d67be174a12b_hd.jpg" data-rawwidth="781" data-rawheight="545" class="origin_image zh-lightbox-thumb" width="781" data-original="https://pic4.zhimg.com/1afe7af6dfbc15a89d37d67be174a12b_r.jpg">
严肃说来,HTML是否被认为是“真正”的编程语言并不重要——它依然是一种需要学习的新技能。尝试新的东西是非常可怕的。你需要在处于这种未知的弱势地位时也敢于勇往直前,不要急头急脑一下子就想把东西学会,要沉得住气,踏踏实实的心态一点一点的来,而且失败和不确定也没有关系—— 事实上,它们都是成功的重要组成部分。
再说下js
在上面我已经阐述过了javascript,(简称js),但是在这里为什么还要再强调js呢?
因为很多人都说不用学js了,直接学jquery(简称jq)就行。jq是什么,jq是一种js的框架,它可以使开发速度更快,有很多做好的功能和特效,直接使用就行了。
但我并不同意光学jq,如果你想让自己能解决更复杂的问题,变得更有竞争力,或者只仅仅能更好的学习理解使用jq。那么请学习js!
上面说了jq是js的一种框架,它的本质还是js写的。js能完成的,理论上来说jq也能完成,但是并不是100%都能处理,而且jquery能做的,js 100%能完成。jquery只是工具简化操作,底层还是js。只有在学好原生js的基础上,才能更好的学习jquery或其它框架和处理前端问题。
后端:
到这里才说到我们的PHP。如果说HTML和css是看得见的部分,那么PHP就是看不见的部分。它负责在后面处理数据,然后返回给用户。
当网站由开始的静态页面发展到现在有了后端程序,那么网站才有了业务逻辑。简单的说,就像一台计算器,你在前端输入数据,然后点击提交,PHP给你处理运算,然后返回到前端,这时你就看到了结果。需要特别说明的是PHP并不能直接在浏览器中运行,它需要Apache环境支持,放在Apache服务器里面,然后用浏览器用访问,这个需要大家在学习过程中配置一下,非常简单。
我的学习技巧和心得
学习PHP我推荐韩顺平老师的《PHP从入门到精通》的视频教程,做PHP开发,包括有了解的同学可能都知道韩顺平老师,名气很大,它的这个教程几乎是每个PHP学子必看的精品教程。网上有很多这个教程的下载。其实韩老师不只是出了这一个教程,大家可以顺便搜一下每学网,每学网上有更多韩老师亲自做的其他教程。
我学习PHP时,慢慢的随着讲解的知识不断增多,不懂的问题也开始出现,刚开始时我就简单用脑子记着,想以后再解决。但是后来再回想,发现有一些竟然记不起来了,慢慢的,不懂的问题越积越多,我害怕遗忘掉我不想遗漏任何我没学会的地方,哪怕是一个暂时没细想,细想一下就能懂的简单问题。如果忘掉了,可能以后再也想不起来了,这对我来说是个很难弥补的损失,我是个完美主义者。
我想起了学习html时的教训,还是不能懒!我建立了一个文本,专门记载我不懂的,难以理解的,还有暂时没有解决的种种问题,甚至是灵机一动偶然想到的问题,也都统统不拉的记下来。
当我学完PHP后,再回头看,数一数大概百十条,这个文本我依然保留着:
<img src="https://pic4.zhimg.com/50/c3214866529991a562bf13627980ecc3_hd.png" data-rawwidth="817" data-rawheight="802" class="origin_image zh-lightbox-thumb" width="817" data-original="https://pic4.zhimg.com/c3214866529991a562bf13627980ecc3_r.png">
我希望大家在学习的过程中也能养成写记问题的习惯,好记性不如烂笔头么,因为学习过程中难免会碰到很多不懂的问题,但是你又不能一直等着这个问题解决,你需要继续前进,而时间久了,你可能就会遗忘掉。
每学到一个脚本难点的时候,尝试对别人讲一遍,你能讲清楚才说明你真的理解了。
除了记问题,我还把老师讲的知识,用自己的话按自己的理解自己的话写下来,这就如同是跟别人讲一遍似得。记住,要用自己的话自己的思路写,忘记老师的原话,这样别人的知识才会转化成你的。
所以,这是我当时写的笔记:
<img src="https://pic3.zhimg.com/50/36dcaccf94220f5ed4864926b3dd09ee_hd.png" data-rawwidth="1023" data-rawheight="484" class="origin_image zh-lightbox-thumb" width="1023" data-original="https://pic3.zhimg.com/36dcaccf94220f5ed4864926b3dd09ee_r.png">
写到这里,大家不要觉得我太麻烦,这样太慢,记住,思考要慢,慢的为了以后更快!
合理的“慢”,不是速度上的缺失,而恰是对“过快”的反思与矫正。慢是一种方法。尊重规律,沉下心来,追求质量,做起事来,严格有序,精益求精。
实践也是强化知识理解的过程
千万不要只看教程和学知识点,最重要的是实践,大多数人包括我,曾都是跟别人学起来像是学会了,到了自己做的时候却很难进行下去。
当你看完教程掌握了里面所述的内容后,可以按照老师讲的例子或者自己构思某个应用场景,然后从头写起。你会发现很多问题,也会加深对教程知识的理解。这样通过不断地练习和获取反馈,你的开发功底会很快提升。
MySQL数据库
当网站技术再往后发展时,人们需要网站处理存放更多的数据,来满足现实生活中的业务逻辑,这时候就需要数据库了。
数据库是什么,按字面的意思,数据库说白就是存放数据的地方,它可以是一段文字,一张图片或者一个文件的URL地址等等。比如,当你想浏览一篇文章时,你点击文章标题,这个请求会跳转到PHP文件那里,PHP再从数据库取出你想看的那篇文章。
PHP和数据库是密不可分的,PHP后来在网站开发中更多的任务就变成了操纵数据库了。数据库有很多种,准确的说咱的这个数据库是mysql数据库,只是因为php和mysql关系非常好,它们两个是完美的搭配。所以我们学习PHP开发学习的数据库就是MySQL数据库。
我的学习技巧和心得
学习mysql时,我同样采用了学习PHP时的学习方法:记问题,写笔记。
还是想在强调一遍:要用自己的话写,忘记老师的原话,这样别人的知识才会转化成你的。
同样,这也是当时我做的:
<img src="https://pic4.zhimg.com/50/aaa9297d66ab00458395aafd7aa7ac27_hd.png" data-rawwidth="1707" data-rawheight="906" class="origin_image zh-lightbox-thumb" width="1707" data-original="https://pic4.zhimg.com/aaa9297d66ab00458395aafd7aa7ac27_r.png">
该通过做一个小项目强化一下了。比如去做一个文章或者商品管理系统,做做常用的增删改查。就像下面的添加这个商品功能页面,无非就是用PHP把前端用户填写的数据存放到数据库。
<img src="https://pic2.zhimg.com/50/dfd275b93b32b095968a73aab8363101_hd.png" data-rawwidth="860" data-rawheight="495" class="origin_image zh-lightbox-thumb" width="860" data-original="https://pic2.zhimg.com/dfd275b93b32b095968a73aab8363101_r.png">
编程只会在最初的几天里是个有意思的事情,之后大多会出现厌烦厌学。所以兴趣并不能完全成为编程的动力。通过项目开发,你会发现更多的编程动力是生活中需要的实际需求和通过高强度高密度的学习和思考后解决需求后的强烈成就感。
框架:
框架说白了就是一个已经帮你完成了部分功能的程序部件结构。
基本上到了公司动手做起真实的项目中都是使用框架来开发的,它可以使你的开发速度更快。
为什么?就说网站开发吧,比如你要做网站中的验证码功能,你需要动手自己从0开始写,同样的,写一个文件上传程序,你需要动手从0开始写。
这时你会问,我做什么不都是要动手写的吗?
但是你忽略了一个问题,验证码,上传文件等等这些都是网站中几乎不可缺少的基本功能,每个网站都要用到,这时候你可以动手把这些常用的功能写好,然后封装起来,用的时候直接调用就行了,大大减少了代码的重复性,而这其实也就是框架了。
Don’t talk about making a framework yourself, because completing a good framework is not a simple and easy task, and it requires a high level of knowledge and technology. Therefore, we need to learn to use professional frameworks made by others. Most small and medium-sized companies use other people’s frameworks. Common PHPs include thinkphp, ci, and yii. I personally recommend learning thinkphp. This is made by Chinese people and is lightweight. Level, it is easier to learn and more companies use it.
MySQL optimization technology:
After you learn PHP and some addition, deletion, modification and query techniques of mysql, you can try to make a simple article management system that can publish and modify , and view the article.
But, just imagine, will you encounter such a problem: when you view an article, MySQL needs to find the article you need from the article table and take it out. At this time, your article has already been There are a lot. For example, if there are one million or ten million articles, will it become more and more time-consuming for mysql to find an article in it? Normally, when the number of articles is small, it may take one second to open an article. , this may take ten seconds. Are you willing to wait? Are users willing to wait? For large news websites like Sina and Tencent, if users have to wait a long time to read a news article, is that okay?
So we need to optimize mysql so that the database can find what we need in as little time as possible.
I won’t discuss the specific technical details here.
Optimization methods mainly include:
1. Table design Reduce data redundancy and save disk overhead)
2, MySQL index optimization (Accelerate the inquiry)
4, partition table (divide a large table into several small tables, improve the speed of the query)
## You can refer to the ones I introduced in your subsequent studies.
Then what I learned about mysql optimization was also the tutorial by Han Shunping, called "Han Shunping's Large Portal Mysql Optimization Technology"
Address: Han Shunping's Large Portal Mysql Optimization Technology on Mixue.com (full version )[Limited-time special course, exclusively equipped with authoritative PPT class notes and exercises]
Page staticization technology:
When you learn MySQL optimization technology, don’t be complacent, new There are still many problems.
You can think about it again: when one person visits, and when a large number of people visit? When you visit alone, it may be very fast, but when a large number of people visit, mysql has to handle a large number of requests, and it is overwhelmed. The number of requests supported by mysql is limited, which is easy to understand.
If it can only handle 100 requests at a time, when there are more than 100 people, will other users have to wait, so the speed will slow down again, as above In the examples of Sina and Tencent, users cannot wait.
what to do? A good solution is to use staticization techniques.
Why should staticization be used? That is to generate a file from the database data. When the user accesses it for the first time, mysql still takes it from the database. When the user accesses it for the second time or even more times in the future, it will access it directly. This static file no longer bothers the database, which reduces the pressure on the server.
Recommended tutorial: "Han Shunping Large Portal Website Page Staticization Technology (Full Version)"
Address: http://www.imeixue.cn/Course-Index-course-id-16. html
Linux
Our programs, databases, and the entire website are ultimately placed on the Linux system server. For ordinary programmers, basic configuration is enough . Basic commands, operations, startup, basic service configuration (including rpm installation files, various service configurations, etc.); can write simple shell scripts and awk/sed script commands. Generally, companies have corresponding operation and maintenance personnel to manage this. If you are interested, you can continue to dig deeper later.
##Non-relational database Redis/Memcached
##Why not learn MySQL directly?
Because: MySQL is more suitable for mass storage of data. Redis and Memcached are in memory and require a large amount of memory. Moreover, the data placed in the memory is easily lost. If the machine fails and is restarted, the memory will be released.
Most Internet companies generally use MySQL + Redis, or MySQL +Memcached for architecture; Redis/Memcached are both based on memory, so they are very fast, including Reading and writing are both fast, and are generally used in scenarios with high concurrency and large data access.
Recommended video tutorial: "Han Shunping Large Portal Memcached Caching Technology (Full Version) Exclusively Equipped with Authoritative PPT Class Notes Practice Questions"
Address: Han Shunping Large Portal of Every Learning Network Memcached caching technology (full version) [Limited-time special course, exclusively equipped with authoritative PPT class notes and exercises]
"Han Shunping Redis Classic Introductory Video Course"
Address: Han Shunping Redis Classic on Mixue.com Introductory Video Course
#In the end, in short, learning PHP is not difficult, what is difficult is a system. What I wrote is generally relatively basic, mainly for students who are just starting to learn, and to establish a complete knowledge system as a whole.
****************************************** *************************************************** *************
On this road, you may still encounter problems that are difficult to understand despite your efforts. Similarly, I once suffered from insomnia for half a month in order to think about solving those difficult problems.
What I want you to know is this:
It is impossible to master every idiosyncrasy of a programming language - they are wildly difficult. If you think programming is a simple skill that is easy to learn, you may be thinking the opposite. As a programmer, there's no limit to what you need to learn, and a persistent sense of insatiable regret that even experts in the field have from time to time.
Don’t worry, after knowing this, put your mind in the right place, and take it step by step. Don’t try to master everything at once. Set up something like “I want to learn how to Write code” - the goal should be more specific and break the task into smaller tasks. Don't give up. Absorbing knowledge is the first step to becoming good at it. You must give yourself confidence and try to think about a problem in more ways.
As the saying goes: Whether you think you can do it or you think you can’t...it all depends on how you hint to yourself. is my constant excuse:
The reason I don’t understand this is because I have a creative brain. And programming is logical, my brain is just not used to this way of thinking!
During the entire learning process, I hope everyone:
Don’t believe in any ‘myths’ and learn to think for yourself.
Don’t stick to the rules, what most people know may be wrong.
Don’t believe the rumors on the Internet, dare to question, test, and make decisions based on practice
The above is the detailed content of The ideas and methods for newbies to learn PHP are reprinted from Zhihu. For more information, please follow other related articles on the PHP Chinese website!