In order for you to learn PHP better, this time I mainly want to talk about the PHP learning route, sort out the technical requirements for PHP programmers at each stage, and set learning and growth goals according to your own situation.
Learning routes and suggestions for PHP beginners
We need to have a step-by-step learning process. Here we first summarize the process of learning PHP, which is similar to that of many enthusiasts who learn PHP. It coincides with each other:
(1) Familiar with HTML/CSS/JS, and basic elements of web pages. In the completion stage, you can make simple web pages by yourself, and you are relatively familiar with element attributes
(2) ) Understand the concepts and operating mechanisms of dynamic languages, and be familiar with basic PHP syntax
(3) Learn how to combine PHP with HTML to complete simple dynamic pages
(4) Contact learning MySQL, start designing the database
(5) Continue to consolidate PHP syntax, be familiar with most of the common PHP functions, understand object-oriented programming, MySQL optimization, and some templates and frameworks
(6) Finally Complete a fully functional dynamic site
Novices should not think that learning PHP is very simple after seeing the above summary. Programming requires serious thinking and continuous practice. The following is a detailed explanation of the PHP learning route. First of all, any website is composed of web pages. In other words, if you want to complete a website, you must first learn to make web pages. Mastering the technology of making static web pages is a prerequisite for learning to develop websites. Therefore, we need to learn HTML to lay the foundation for making websites in the future. Learning HTML should be done while learning. Any element in HTML must be practiced personally. Only after you understand what element will have what effect can you remember it deeply. Just reading a book will not work.
Assuming that you can already do it After completing a static page, it’s time to start understanding dynamic languages. Many people may have a lot of confusion when they first come into contact with dynamic languages. The code is not output directly, but needs to be processed. HTML is processed by an HTML parser. And PHP also needs to go through the PHP parser. Just like learning HTML, if you want any parser to work, you must use its dedicated grammatical structure
When you learn PHP, you should feel lucky, because if you learn After using other languages, you will find that PHP is still relatively simple. At this stage, you need to understand the concepts of HTML and PHP. You can now let PHP calculate one plus one, and then add it to the number in the browser. output. Don't feel naive. Although this is a small piece of code, it is a big step forward in your programming journey. But now, you are still a rookie
Next, you have to learn the database. MySQL can be said to be the golden partner of PHP. We want to conquer this database. After you understand the concept of database, you must try to use PHP to connect to the database, and then use PHP to successfully insert, delete and update data
At this time, you may be in this state: Do you know HTML? Yes, I can compile several web pages with table layouts! Do you know PHP? Yes, I will write the operation of one plus one in the function and then call it! Do you know MySQL? Yes, I can insert and delete data in the database!
So what should we do next? Try making a small guestbook. This is also a hurdle faced by novices. After a while, you finally learned to insert the form data into the database and then displayed it. It should be said that the prototype of a program has been born. However, you may look at someone's editing forum or developing CMS. When can I write one? Don't worry, consolidate your knowledge and become familiar with the essentials of PHP and MySQL development. Then look back at the guestbook you wrote. You may wonder if it was really written by you? At this time, you can improve the guestbook you wrote. The guest book should have registration and paging functions. If possible, the UI can also be enhanced
Does this count as learning? NO, NO, NO, it’s still early. You haven’t touched OOP yet, right? What about templates and frameworks? Still have to continue learning! The PHP framework provides a basic framework for building web applications, thereby simplifying the process of writing web applications in PHP. It can save development time and help build more stable applications. So, PHP framework is a tool that can be used to save time and enhance your code. When you choose a PHP framework for the first time, it is recommended to try several. Each framework has its own strengths and weaknesses. For example, the Zend framework has been popular for a long time due to its diverse functions, and a wide support system. And c++akePHP is a PHP framework later than Zend, and the corresponding support system is relatively small, but it is more convenient and easier to use
After understanding object-oriented and frameworks, you should get in touch with XML. All in all, you will never find that you have learned it all, and there is no end to learning! When learning something, never assume that you can achieve it quickly. No matter how many skills you have, it will be in vain if you lack hard work. One thing that can be guaranteed is that if you learn PHP, then you will definitely learn other languages quickly. Vice versa, if you have learned other languages before, then you will definitely learn PHP quickly
It is definitely beneficial to learn more from other people's successful codes, so looking at those classic codes that have been refined over time is the best way to make progress. In addition, it should be emphasized that you may encounter difficulties and get confused when learning a technology. You may have learned half of PHP and start thinking about C# again, or someone may say that Java is very good. At this time, you must not Wave, persist, and learn thoroughly.
Let’s discuss the learning process in stages:
First stage: Basic stage (basic PHP programmer)
Focus: Become proficient in LNMP (the core is Basic operations of installation and configuration)
Objective: Be able to complete basic LNMP system installation, simple configuration and maintenance; be able to do basic PHP development of simple systems; be able to support the development of a certain PHP function module in a medium-sized PHP system.
Time: The time to complete this stage varies from person to person. Some grow faster and it takes half a year, while others grow slowly in two or three years.
1.Linux
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 wait.
2.Nginx
Be able to install and configure nginx+php, know the basic nginx core configuration options, know basic configurations such as server/fastcgi_pass/access_log, the goal is to make nginx+php_fpm smooth Work.
3.MySQL
Can build mysql by myself, know the basic mysql configuration options; know the difference between innodb and myisam, know the different configuration options for the two engines of InnoDB and MyISAM; know the basic The difference between the two engines and the difference in selection; being able to compile and build a MySQL database purely by hand and configure the encoding to run normally and stably; the core purpose is to be able to build a runnable MySQL database.
4.PHP
Basic syntax array, string, database, XML, Socket, GD/ImageMgk image processing, etc.; familiar with various APIs linked to MySQL operations (mysql/mysqli/ PDO), know how to solve various coding problems; know the commonly used PHP frameworks (ThinkPHP, Zendframework, Yii, Yaf, etc.); understand the basic MVC operating mechanism and why it is done, and know a little about the differences between different PHP frameworks ;Be able to quickly learn an MVC framework. Be able to understand the file directory organization in the development project, have a basic good code structure and style, and be able to complete the development of small systems and the development of a certain module in a medium-sized system.
5. Front-end
If conditions and time permit, you can learn HTML/CSS/JS and other related knowledge appropriately, know what web standards, web/wap page mode of div+css, and know HTML5 The difference from HTML4; understand some basic front-end and JS frameworks (jQuery and the like); understand some basic JavaScript programming knowledge; (This item is not required. If you have time, it is okay to learn a little bit about it, but it is not recommended. as a focus, unless there is a strong personal interest).
6. System design
Be able to complete the basic design of a small system, including simple database design, and be able to complete the basic: browser-> Nginx+PHP -> database architecture design Development work; able to support the development and maintenance of websites with hundreds of thousands to millions of traffic every day;
Second stage: improvement stage (intermediate PHP programmer)
Focus: improve LNMP skills to be able to apply LNMP more comprehensively and proficiently.
Goals: Be able to set up an LNMP environment anytime and anywhere and quickly complete routine configurations; be able to trace and solve most of the development and online environment problems encountered; be able to independently undertake the architecture and development work of medium-sized systems; be able to Undertake the development work of a medium-sized module in a large system.
1. Linux
On the basis of the first stage, you can smoothly use Shell scripts to complete a lot of automated work; awk/sed/perl also operates well and can complete a lot of text. Processing and data statistics; basically able to install most non-special Linux programs (including various libraries, packages, third-party dependencies, etc., such as MongoDB/Redis/Sphinx/Luncene/SVN, etc.); understand basic Linux Services, know how to view Linux performance indicator data, know basic problem tracking under Linux, etc.
2. Nginx
Based on the first stage, understand the more complex Nginx configuration; including multi-core configuration, events, proxy_pass, sendfile/tcp_* configuration, know timeout and other related configurations and Performance impact; know that in addition to web server, nginx can also undertake proxy server, reverse static server and other configurations; know basic nginx configuration tuning; know how to configure permissions, compile an nginx extension to nginx; know the basic nginx operating principle (master /worker mechanism, epoll), know why nginx performance is better than apache performance and other knowledge.
3. MySQL/MongoDB
On the basis of the first stage, in terms of MySQL development, master many tips, including conventional SQL optimization (group by/order by/rand optimization, etc.); in addition to being able to build MySQL, you can also hot and cold backup MySQL data. I also know the configuration options that affect the performance of innodb/myisam (such as key_buffer/query_cache/sort_buffer/innodb_buffer_pool_size /innodb_flush_log_at_trx_commit, etc.), and I also know the appropriate values for configuring these options; I also know some special configuration options, such as knowing how to set up a mysql master-slave Synchronous environment, know the difference between each binlog_format; know the performance tracking of MySQL, including slow_log/explain, etc., and also know the basic index establishment processing and other knowledge; understand the basic MySQL architecture (Server + storage engine) in terms of principles, and know the basic InnoDB/MyISAM index storage structures and differences (clustered index, B-tree); know the basic InnoDB transaction processing mechanism; understand the solutions for most MySQL exceptions (or know where to find the solutions). If conditions permit, it is recommended to learn about MongoDB, a representative database of NoSQL, and compare the differences with MySQL. Colleagues can use MongoDB safely and prudently in suitable application scenarios, and know the basic combined development of PHP and MongoDB.
4. Redis/Memcached
In most medium-sized systems, cache processing will definitely be involved, so you must understand the basic cache; know the similarities, differences and application scenarios of Memcached and Redis, and be able to independently Install Redis/Memcached, understand some basic features and limitations of Memcahed, such as the maximum value, and know how to combine PHP with their use; understand the basic working principles and usage of Redis, understand regular data types, and know which types are used in what scenarios. Redis transactions and so on. In the principle part, you can have a general understanding of the memory structure of Memcached (slab mechanism). Redis understands the underlying implementation storage structure of common data types (SDS/linked list/SkipList/HashTable), etc. By the way, you can learn more about Redis's transactions, RDB, AOF and other mechanisms. good.
5. PHP
In addition to the first stage capabilities, in terms of installation and configuration, you can freely install the compilation and installation configuration of PHP and various third-party extensions; understand most of the configuration options of php-fpm and Meaning (configurations that affect performance such as max_requests/max_children/request_terminate_timeout), know the difference between mod_php/fastcgi; have become proficient in various basic technologies in PHP, including various more in-depth PHP, including object-oriented knowledge of PHP Have an in-depth understanding of the special features at the /SPL/ syntax level such as reflection; have read the code of at least one conventional PHP MVC framework in terms of frameworks, and know the internal implementation mechanism and design ideas of the basic PHP framework; have been able to develop in PHP Proficient in using conventional design patterns for application development (abstract factory/single case/observer/command chain/strategy/adapter, etc.); it is recommended to develop your own PHP MVC framework to fully liberalize development and allow yourself to deeply understand the MVC pattern. It also allows you to quickly upgrade in business project development; be familiar with various code optimization methods of PHP, and be familiar with solving most PHP security issues; be familiar with the basic PHP execution mechanism principles (Zend engine/extended basic working mechanism).
6. C/C++
Start to dabble in a certain C/C++ language, be able to write basic C/C++ code, and be familiar with basic C/C++ syntax (pointers, array operations, characters Strings, regular standard API) and data structures (linked lists, trees, hashes, queues); have a basic understanding of C language development concepts under Linux, be able to write simple makefile files, and be able to use simple GCC /GDB program compilation and simple debugging work; have a general understanding of basic network programming. (This item is to lay the foundation for a higher level).
7. Front-end
On the basis of the first stage, be familiar with the basic HTTP protocol (protocol code 200/300/400/500, basic HTTP interaction header); conditions permit, you can In-depth writing of slightly elegant HTML+CSS+JavaScript, or the ability to use some front-end frameworks (jQuery/YUI/ExtJS/RequireJS/BootStrap, etc.); if conditions permit, you can in-depth study JavaScript programming, such as the closure mechanism , DOM processing; if you want to go deeper, you can read the jQuery source code for in-depth study. (This item is not a key study unless you are interested in the front-end).
8. System Design
Be able to design website architecture, database, and basic PHP framework selection for most medium-sized systems; perform performance testing and troubleshooting, etc.; be able to complete tasks similar to: Browser-> CDN (Squid) -> Nginx+PHP -> Cache-> Basic design, development and maintenance of database structure websites; capable of supporting the development and maintenance of basic websites with millions to tens of millions of traffic every day;
Third Stage: Advanced stage (senior PHP programmer)
Key points: In addition to basic LNMP programs, you can also have in-depth study in a certain direction or field. (Depth Dimension Development)
Goal: In addition to being able to complete basic PHP business development, you can also solve most in-depth and complex technical problems, and you can independently design and complete medium and large-scale system design and development work; you can independently Hold goes deep into a certain technical direction and is relatively professional in this area. (For example, in-depth research in any direction such as MySQL, Nginx, PHP, Redis, etc.)
1. Linux
In addition to the second stage capabilities, in addition to regular operations and performance monitoring and tracking under Linux, you can also use many advanced and complex commands to complete the work (watch/tcpdump/starce /ldd/ar, etc.); in terms of shell scripts, I have been able to write relatively complex shell scripts (more than 500 lines) to assist in completing many shell tasks including backup, automated processing, monitoring, etc.; I have become proficient in applications such as awk/sed/perl, and can control and process text statistics at will. Analyze data in various complex formats; have some understanding of the internal mechanisms of Linux, and have basic processing of kernel module loading, startup error handling, etc.; also understand some other related things, such as NFS, disk management, etc.;
2. Nginx
On the basis of the second stage, I have been able to operate Nginx very proficiently and can perform more in-depth operation and maintenance work on Nginx, such as monitoring, performance optimization, complex Problem solving, etc.; depending on personal interests, you can consider focusing on in-depth study of the working principle of Nginx in more aspects, mainly starting from reading the source code, such as the specific master/worker working mechanism, Nginx internal event processing, memory management, etc. etc.; at the same time, you can learn the development of Nginx extensions and customize some of your own private extensions; at the same time, you can have a certain degree of understanding of Nginx+Lua to see if a better model can be combined and applied; the requirement at this stage is to understand the principles of Nginx With an in-depth understanding, you can consider becoming an in-depth professional in the Nginx direction.
3. MySQL/MongoDB
Based on the second stage, in terms of MySQL applications, in addition to the previous basic SQL optimization, it can also complete some complex operations, such as large batches of data. High-risk operations such as importing and exporting, changing table structures or adding or deleting index fields for online large batches of data; in addition to installation and configuration, it has been able to handle more complex MySQL problems, such as tracing various problems and solving master-slave synchronization delay problems. , cross-computer room synchronization data solutions, MySQL high-availability architecture, etc.; are familiar with MySQL application level, familiar with the core key technologies of MySQL, such as transaction mechanisms (isolation levels, locks, etc.), and have knowledge of triggers, partitions and other technologies Must understand and apply; for MySQL performance, including disk optimization (SAS migration to SSD), server optimization (memory, server itself configuration), other core performance optimization options in addition to the second stage (innodb_log_buffer_size/back_log /table_open_cache/thread_cache_size/innodb_lock_wait_timeout etc.), connection pool software selection application, in-depth understanding of operation statements such as show * (show status/show profile), and able to complete most performance problem tracing; in-depth familiarity with MySQL backup technology, including disaster recovery and recovery, and Binlog In-depth understanding of hot and cold backup, multi-IDC backup, etc.; in terms of MySQL principles, have a better understanding, such as starting to read part of the source code for the working mechanism of MySQL, such as learning the source code of master-slave synchronization (replication) technology, or learning about a certain Learn and understand the source code of storage engines (MyISAM/Innodb/TokuDB), etc. If conditions permit, you can refer to the CSV engine to develop your own simple storage engine to save some data and enhance your understanding of MySQL; in this process, if you are interested , you can also consider developing in the direction of DBA. At the MongoDB level, you can consider, for example, starting to apply MongoDB online when writing less and reading more, or doing some online data analysis and processing operations. The specific scenarios can be based on the work, but the core is to have a better and in-depth understanding of RMDBS. For applications in different scenarios from NoSQL, if conditions or interests permit, you can start to learn more about the working mechanism of MongoDB.
4. Redis/Memcached
On the basis of the second stage, more in-depth application and learning can be achieved. Because Memcached is not particularly complex, it is recommended to read the source code, especially the memory management part, to facilitate in-depth understanding; in the Redis part, you can do more complex data structure applications (zset is used for ranking ranking operations/transaction processing to ensure Atomicity is used in flash sale scenario applications); it mostly involves learning applications of synchronization mechanisms such as aof, and designing a highly available Redis application architecture and cluster; it is recommended that you study the source code of Redis in depth and put it into the second stage The accumulated knowledge can be applied. In particular, you can read about core event management, memory management, internal core data structure, etc. to fully understand it. If your interest allows, you can become a very professional user of Redis.
5. PHP
As basic core skills, we need more in-depth study and application based on the second stage. In terms of basic code application, you can solve 95% of the problems encountered in PHP development and understand most PHP techniques; you can quickly start using most PHP frameworks within a day, and understand the advantages of each mainstream PHP framework. Disadvantages: It can quickly and conveniently make technology selection in project development; in terms of configuration, in addition to the knowledge of the regular second stage, you will also understand some more obscure configuration options (php auto_prepend_file/auto_append_file), including some complex advanced configurations in extensions and principles (such as memcache.hash_strategy in the memcached extension configuration, apc.mmap_file_mask/apc.slam_defense /apc.file_update_protection in the apc extension configuration, etc.); have a good understanding of the working mechanism of php, including the php-fpm working mechanism (such as php-fpm enables process number calculation and principle under different configuration machines), has basic familiarity with the zend engine (vm/gc/stream processing), has read the basic PHP kernel source code (or read related articles), and has an understanding of the internal mechanism of PHP Have an understanding of the implementation of most core data structures (basic types/Array/Object), and have an in-depth understanding of the core infrastructure (zval/hashtable/gc); be able to carry out basic PHP extension development, and understand some intermediate and advanced knowledge of extension development (minit/rinit, etc.), be familiar with the details of different communication and interaction methods between php and apache/nginx (mod_php/fastcgi); in addition to developing PHP extensions, you can consider learning to develop Zend extensions to understand PHP from a lower level.
6. C/C++
On the basis of the second stage, you can have a deeper understanding of the C/C++ language and be able to complete the development of small and medium-sized C/C++ systems; In addition to the basic C/C++ syntax and data structures in the second stage, you can also learn some special data structures (b-tree/rb-tree/skiplist/lsm-tree/trie-tree, etc.) to facilitate your needs in special work; In terms of system programming, you are familiar with multi-process and multi-thread programming; understand most of the communication methods between multi-processes in multi-process situations, and be able to flexibly choose communication methods (shared memory/semaphore/pipeline, etc.); multi-thread programming can solve the problem well Lock conflict problems, and be able to develop and debug multi-threaded programs; at the same time, be familiar with network programming, understand the differences and selection of multi-process models/multi-thread models/asynchronous network IO models, and be familiar with the principles and selection of different asynchronous network IO models Differences (select/poll/epoll/iocp, etc.), and be familiar with common asynchronous frameworks (ACE/ICE/libev /libevent/libuv/Boost.ASIO, etc.) and their use. If you have time, you can also take a look at some domestically developed libraries ( Such as muduo); at the same time, be able to design a good high-concurrency program architecture (leader-follow/master-worker, etc.); understand most of the problems in C/C++ back-end server development (memory management, log printing, high concurrency, front-end and back-end communication Protocol, service monitoring), know the RPC communication issues of various back-end services (struct/http/thirft/protobuf, etc.); be more familiar with using GCC and GDB to develop compilation and debugging programs, and be able to quickly trace and track after the online program core is lost Solve problems; in terms of general module development, you can accumulate or develop some general tools or libraries (such as asynchronous network frameworks, log libraries, memory pools, thread pools, etc.), but you must be careful whether to apply them after development to save yourself from chasing bugs. .
7. Front-end
In-depth understanding of the HTTP protocol (including the special protocol codes of each detailed protocol and the reasons behind it, such as 302 static files are cached, 502 means that php behind nginx is down, etc.); In addition to the previous front-end application integration capabilities of various frameworks, if you are interested in learning the front-end aspect, you can go deeper. In the form of developing some front-end frameworks like jQuery yourself, or developing a rich text editor, which is relatively trivial. Test your JavaScript skills.
8. Language learning in other fields
Have basic accumulation in basic PHP/C/C++ language. It is recommended that you try to learn different programming languages at the current stage, depending on personal interests and hobbies, scripts For class languages, you can learn Python/Ruby and the like. For functional programming languages, you can try Lisp/Haskell/Scala/Erlang. For static languages, you can try Java/Golang. For data statistical analysis, you can learn about the R language. If you want To change the perspective of back-end business, you can try Node.js and the aforementioned Nginx_Lua combined with Nginx. Learning different languages is mainly about improving your own vision and the differences in problem-solving methods. For example, you will understand that in addition to processes/threads, there are also lightweight coroutines; for example, in cross-machine communication scenarios, Erlang’s solution is surprisingly simple; for example If you don't want to choose C/C++, there are also similar efficient Erlang/Golang available, etc.; mainly to improve your horizons.
9. Study in other professional directions
In this stage, in addition to basic LNMP skills, we will also consider learning knowledge in other fields. These are all possible, depending on personal interests and long-term goals. At present, there are many fields to choose from, such as cloud computing (distributed storage, distributed computing, virtual machines, etc.), machine learning (data mining, pattern recognition, etc., applied to statistics, personalized recommendations), natural language processing ( Chinese word segmentation, etc.), search engine technology, graphics and images, speech recognition, etc. In addition to these advanced ones, there are also many areas where you can learn more about engineering, such as high-performance systems, mobile development (Android/IOS), computer security, embedded systems, hardware, etc.
10. System Design
Based on the second stage, system design can apply the experience and skills mastered to design relatively complex medium and large-scale systems, which can solve most online problems. Various complex system problems, such as browser-> CDN -> load balancing-> access layer-> Nginx+PHP -> business cache-> database-> various complex back-end RPC Interaction (storage backend, logic backend, anti-cheating backend, external services) -> More complex business of backend Jiangzi; able to support the normal development and maintenance of tens to hundreds of millions of traffic websites every day.
Finally, share 10 tips for PHP performance optimization to help you better develop with PHP:
1. Foreach is more efficient, try to use foreach instead of while and for loop
2. Do not declare variables inside loops, especially variables such as objects
3. In multiple nested loops, if possible, the longest loop should be placed in the inner layer , the shortest loop is placed in the outer layer, thereby reducing the number of times the CPU crosses the loop layer and optimizing program performance
4. Use single quotes instead of double quotes to quote strings to achieve PHP performance optimization
5. , use i+=1 instead of i=i+1. In line with the habits of c/c++, the efficiency is still high
6. Optimize the Select SQL statement and perform as few Insert and Update operations as possible to achieve the purpose of PHP performance optimization
7 ,, try to do as few file operations as possible, although PHP's file operation efficiency is not low
8., Use PHP internal functions as much as possible
9., You can use PHP internal characters In the case of string operation functions, do not use regular expressions
10. Feof, fgets, fopen, and when file_get_contents can be used instead of file or series methods, try to use file_get_contents because it is much more efficient. . But please pay attention to the PHP version problem of file_get_contents when opening a URL file