Learning routes and suggestions for PHP beginners
We need to have a step-by-step learning process. here we will summarize the process of learning PHP, which is consistent with that of many PHP enthusiasts:
(1) familiar with HTML/CSS/JS and basic webpage elements. you can create a simple webpage by yourself at the completion stage and be familiar with Element attributes.
(2) understand the concept and operating mechanism of dynamic language, and be familiar with basic PHP syntax
(3) Learn how to combine PHP with HTML to complete simple dynamic pages
(4) learn MySQL and start designing databases.
(5) constantly consolidate PHP syntax, familiarize yourself with most common PHP functions, understand object-oriented programming, MySQL optimization, and some templates and frameworks
(6) final completion of a fully functional Dynamic Site
Don't look at the above summary, so you think PHP learning is very simple. programming requires you to think carefully and practice constantly. The following describes the learning routes of PHP. First, all websites are composed of web pages. to complete a website, you must first learn how to create a web page. mastering the production technology of static web pages is a prerequisite for learning to develop websites. Therefore, we need to learn HTML to lay the foundation for website production in the future. When learning HTML, you should learn and do it. any element in HTML must be put into practice in person. only by understanding what elements will play what effect can you remember deeply. reading a book without a taste of it will not work.
Assuming that you can complete a static page, you should start to understand the dynamic language. when you get started with the dynamic language, many people may have a lot of questions, and the code is not directly output, however, HTML is processed by the HTML parser, and PHP also needs to use the PHP parser to learn the same principles as HTML and want any parser to work, you must use its dedicated syntax structure.
You should be lucky to learn PHP, because if you have learned other languages, you will find that PHP is relatively simple. at this stage, you need to understand the concepts of HTML and PHP, now you can let PHP calculate the sum of one and one, and the number, and then output it in the browser. Don't feel naive. Although this is a small piece of code, it is a huge step for your programming path. But now you are a Cainiao
Next, we will learn about the database. MySQL can be said to be the prime partner of PHP. we want to conquer this database. after you understand the concept of a database, we will try to connect to the database through PHP, the data will be inserted, deleted, and updated successfully using PHP.
At this time, you may be in this state: Do you know HTML? Yes. I can compile several page la s! Do you know PHP? Yes, I will write the one-plus-one operation 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 to make a small message book, which is also a level for beginners. After a while, you finally learned to insert the form data into the database and then display it. it should be said that the prototype of a program has been born. However, you may want to read this editing Forum, the development CMS. When can I write one? Don't worry, consolidate your knowledge, familiarize yourself with the essentials of PHP and MySQL development, and then look back at the message book you wrote. may you doubt that it was actually written by you? At this time, you can improve your message book. The message book should be added with registration and paging functions. If yes, the UI can be enhanced.
How can this be learned? NO, NO, NO. it's still early. Have you ever touched OOP? What about the template and framework? Continue learning! The PHP framework provides a basic framework for building web applications, which simplifies the process of compiling web applications using PHP. It can save development time and help build more stable applications. Therefore, the PHP framework is a tool that can be used to save time and enhance your code. When you select a PHP framework for the first time, we suggest you try a few more. each framework has its own strengths and weaknesses. for example, the Zend Framework has a wide range of support systems due to its diverse features, it has been popular for a long time. C ++ akePHP is a PHP Framework later than Zend, with fewer supported systems, but more convenient and easy to use.
After learning about the object-oriented and framework, you should get into touch with XML. In short, you will never find that you have learned all of them, and there is no end to learning! Never imagine that there are too many skills to quickly learn things, but the lack of effort is nothing to do. One thing you can ensure is that you have learned PHP, and then you will certainly be able to learn other languages quickly. in turn, if you have learned other languages before, you will certainly be able to learn PHP quickly.
Learning from others' successful code is definitely beneficial and harmless. Therefore, it is the best way to learn more about the classic code that has been compiled by a great deal of effort. In addition, you may encounter difficulties and confusion when learning a technology. you may have learned half of PHP and started to develop C, some people may say that Java is good. at this time, you must stick to it and learn it thoroughly.
Next we will discuss the learning process in stages:
Phase 1: Basic Stage (basic PHP programmer)
Focus: get familiar with LNMP (the core is the basic installation and configuration operations)
Objective: to install and maintain the basic LNMP system, develop PHP for the basic simple system, and develop a PHP function module in the PHP medium-sized system.
TIME: The time needed to complete this phase varies from person to person. some of them have grown over half a year, and some have grown slowly for two or three years.
Basic commands, operations, startup, and basic service configurations (including rpm installation files and various service configurations); write simple shell scripts and awk/sed script commands.
Install and configure nginx + php, know the basic nginx core configuration options, and know the basic configurations such as server/fastcgi_pass/access_log. The goal is to make nginx + php_fpm work smoothly.
Will build mysql by yourself, know the basic mysql configuration options, know the differences between innodb and myisam, know the different configuration options for the InnoDB and MyISAM engines; know the differences between the two basic engines and select the above differences; be able to manually build a MySQL database and configure the encoding to run normally and stably; the core objective is to build a runable MySQL database.
Basic syntax array, string, database, XML, Socket, GD/ImageMgk image processing, etc. familiar with various APIs connected to MySQL (mysql/mysqli/PDO ), know how to solve various coding problems, know the PHP framework (ThinkPHP, Zendframework, Yii, Yaf, etc.) that is widely used, and understand the basic MVC operating mechanism and why, know the differences between different PHP frameworks; be able to quickly learn an MVC framework. Be aware of the file directory organization in the development project, have a basic good code structure and style, and can complete the development of a small system and a module in a medium-sized system.
6. system design
Able to complete the basic design of small systems, including simple database design, and complete the basic design and development of the browser-> Nginx + PHP-> database architecture; supporting the development and maintenance of hundreds of thousands to millions of websites each day;
Stage 2: improvement stage (intermediate PHP programmer)
Key points: improve LNMP-specific skills and be able to use LNMP more comprehensively.
Objective: to build an LNMP environment anytime, anywhere, and quickly complete routine configuration; to trace and solve most of the problems encountered in development and online environments; to independently undertake the architecture and development of medium-sized systems; can develop a medium-sized module in a large system.
On the basis of the first stage, we can smoothly use Shell scripts to complete a lot of automated work. awk/sed/perl is also well-operated and can complete a lot of text processing and data statistics; basically can install most non-special Linux programs (including various libraries, packages, third-party dependencies, such as MongoDB/Redis/Sphinx/Luncene/SVN); understand basic Linux services, know how to view the performance indicator data of Linux, know the problem tracking under the basic Linux.
On the basis of the first stage, learn more about complicated Nginx configurations, including multi-core configurations, events, proxy_pass, sendfile/tcp _ * configurations, and related configurations and performance impact such as timeout; know that nginx not only supports web server, but also supports proxy server and reverse static server configurations, know basic nginx configuration optimization, know how to configure permissions, compile an nginx extension to nginx; understand the basic nginx operating principles (master/worker mechanism, epoll), and know why nginx has better performance than apache.
On the basis of the first stage, I have mastered many tips in MySQL development, including regular SQL optimization (group by/order by/rand optimization). apart from setting up MySQL, mySQL data can be backed up in hot and cold ways, and configuration options that affect innodb/myisam performance are also known (such as key_buffer/query_cache/sort_buffer/innodb_buffer_pool_size/innodb_flush_log_at_trx_commit ), you also know the value of these options. you also know some special configuration options, such as how to set up the mysql master-slave synchronization environment and the differences between binlog_format; know the performance tracing of MySQL, including slow_log/explain, and the basic indexing and processing knowledge. learn about the basic MySQL architecture (Server + storage engine) in terms of principles ), know the basic InnoDB/MyISAM index storage structure and Different (clustered index, B-tree); know the basic InnoDB transaction processing mechanism; understand the processing solutions for most MySQL exceptions (or know where to find the processing solution ). If conditions permit, it is recommended that you understand the MongoDB database represented by NoSQL. By the way, we compare the differences with MySQL. colleagues can use MongoDB safely and cautiously in appropriate application scenarios, understand the basic development of PHP and MongoDB.
Cache processing will be involved in most medium-sized systems, so you must understand the basic cache and know the similarities and differences between Memcached and Redis. you can install Redis/Memcached independently, understand some basic features and restrictions of Memcahed, such as the maximum value, and know how PHP works with them. Redis understands basic working principles and usage, and understands common data types, know what scenarios and types of applications, understand Redis transactions, and so on. In principle, we can get a rough idea of Memcached's memory structure (slab mechanism), and redis will understand the underlying storage structure (SDS/linked list/SkipList/HashTable) of common data types, by the way, it is better to understand Redis's transaction, RDB, AOF, and other mechanisms.
In addition to the capabilities of the first stage, PHP and various third-party extensions can be installed at will in terms of installation configuration; understand most of the configuration options and meanings of php-fpm (such as max_requests/max_children/request_terminate_timeout and other factors that affect performance), and know the differences between mod_php and fastcgi; I have already been familiar with various basic technologies in PHP, as well as a variety of in-depth PHP, including in-depth understanding of PHP object-oriented/SPL/special features at the syntax level, such as reflection; I have read at least one common PHP MVC framework code in the framework, and understand the internal implementation mechanism and design concept of the basic PHP framework; in PHP development, you have been able to use regular design patterns for application development (Abstract factory/Singleton/Observer/command chain/policy/adapter ); we recommend that you develop your own php mvc framework to fully enable development liberalization, so that you can deeply understand the MVC model and quickly upgrade your business project development. you are familiar with various PHP code optimizers. Familiar with most PHP security issues, and familiar with basic PHP execution mechanism principles (Zend Engine/Basic Extension working mechanism ).
6. C/C ++
Started with a certain number of C/C ++ languages, able to write basic C/C ++ code, familiar with basic C/C ++ syntaxes (pointers, Array Operations, strings, and standard APIs) and data structures (linked list, tree, hash, and queue; have a basic understanding of the C language development concepts in Linux, write simple makefile files, and be able to use simple GCC/GDB programming for simple debugging; have a rough understanding of basic network programming. (This project aims to lay the foundation for a higher level ).
8. system design
Ability to design the website architecture, database, and basic PHP framework selection for most medium-sized systems; performance testing and troubleshooting; ability to complete similar tasks: Browser-> CDN (Squid) -> Nginx + PHP-> cache-> basic design, development, and maintenance of database structure websites; supporting the development and maintenance of basic websites with millions to tens of millions of traffic per day;
Stage 3: Advanced (advanced PHP programmer)
Important: in addition to the basic LNMP program, you can also have in-depth learning in a certain direction or field. (In-depth development)
Objective: in addition to basic PHP business development, it can also solve most in-depth and complex technical problems and independently design medium and large system design and development; I am able to independently hold a certain technical direction, which is relatively professional. (For example, in-depth research on MySQL, Nginx, PHP, Redis, etc)
In addition to the capabilities of the second stage, in addition to routine operations and performance monitoring tracking in Linux, you can also use a lot of advanced and complex commands to complete the work (watch/tcpdump/starce/ldd/ar). in terms of shell scripts, it has been able to write more complex shell scripts (more than 500 lines) to assist with a lot of shells including backup, automated processing, monitoring, and other work; awk, sed, perl, and other applications have been very popular, allowing you to control and process text statistics and analyze data in various complex formats at will. you have some knowledge about Linux internal mechanisms and load kernel modules, start error handling and so on. at the same time, you can understand other related things, such as NFS and disk management;
On the basis of the second stage, we have been able to skillfully operate and maintain Nginx, such as monitoring, performance optimization, and complex problem handling; if you look at your personal interests, you can focus on the in-depth study of the working principles of Nginx, mainly starting from reading the source code, such as the specific master/worker working mechanism, nginx internal event processing, memory management, and so on. at the same time, you can learn about Nginx extension development and customize some of your own private extensions. at the same time, you can have a certain understanding of Nginx + Lua, check whether a better mode can be used in combination with the application. This stage requires an in-depth understanding of Nginx principles and can be considered as an in-depth professional in the Nginx field.
On the basis of the second stage, in terms of MySQL applications, in addition to the basic SQL optimization, some complex operations can be completed, such as importing and exporting large volumes of data, high-risk operations such as changing the table structure or adding or deleting index fields of online mass data. in addition to the installation and configuration, more complicated MySQL problems, such as troubleshooting of various problems, master-slave synchronization latency, data synchronization across data centers, MySQL high-availability architecture, etc. familiar with MySQL applications and key MySQL technologies, for example, the transaction mechanism (isolation level, lock, etc.), the trigger, partition and other technologies have a certain understanding and application, MySQL performance, including disk optimization (SAS migration to SSD) server Optimization (memory, server configuration), other core performance optimization options (innodb_log_buffer_size/back_log/table_open_cache/thread_cache_size/innodb_lock_wait_timeout), and connection pool software selection Select application and have an in-depth understanding of the show * (show status/show profile) operation statements to trace most performance problems, including disaster recovery and recovery, deep understanding of Binlog, cold/hot backup, and multi-IDC Backup. Learn more about MySQL principles, such as reading some source code about the working mechanism of MySQL, for example, you can learn the source code of the master-slave synchronization (replication) technology or the source code of a storage engine (MyISAM/Innodb/TokuDB). 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 towards DBA. At the MongoDB level, you can consider, for example, starting to apply MongoDB online when writing less and reading more data, or performing online data analysis and processing operations. the specific scenarios can follow the work instructions, however, the core is to better understand the applications in different scenarios of RMDBS and NoSQL. if conditions or interests permit, you can start to learn more about the working mechanism of MongoDB.
On the basis of the second stage, we can further apply and learn. Because Memcached is not very complex, it is recommended that you read the source code, especially the memory management part, to facilitate in-depth understanding; Redis part, you can do more complex data structure applications (zset is used for ranking and sorting operations/transaction processing to ensure atomicity in scenarios such as seckilling ); design a highly available Redis application architecture and cluster for learning applications that involve synchronization mechanisms such as aof. it is recommended that you have a deep understanding of the Redis source code, the knowledge accumulated in the second stage can be applied. For more information, see core event management, memory management, and internal core data structure. If you are interested, you can become a very professional Redis user.
As the basic core skills, we need to have more in-depth learning and application on the basis of the second stage. From the basic code application, it can solve 95% of the problems encountered in PHP development and understand most PHP skills. for most PHP frameworks, it can be quickly used within one day, understand the advantages and disadvantages of various mainstream PHP frameworks, and quickly facilitate technical selection in project development. in terms of configuration, in addition to the knowledge of the regular second stage, you will learn about some of the configuration options (php auto_prepend_file/auto_append_file), including some complex advanced configurations and principles of extensions (such as memcache in memcached extension configuration. apc in hash_strategy and apc extension configuration. mmap_file_mask/apc. slam_defense/apc. file_update_protection). I have a better understanding of the working mechanism of php, including the working mechanism of php-fpm (for example, php-fpm enables the calculation of the number of processes under different configuration machines and the principle ), have basic familiarity with the zend Engine (vm/gc/stream) I have read the basic PHP kernel source code (or read the relevant chapter) and have an understanding of the implementation of most of the core data structures (basic types/Array/Object) in the PHP internal mechanism, have an in-depth understanding of the core infrastructure (zval, hashtable, and gc), be able to perform basic PHP extension development, and learn about some advanced extensions (minit, rinit, and so on ), familiar with the details of different communication and interaction modes (mod_php/fastcgi) between php and apache/nginx. in addition to developing PHP extensions, you can consider learning to develop Zend extensions to learn more about PHP at the lower layer.
6. C/C ++
On the basis of the second stage, you can have a deeper understanding of the C/C ++ language and complete the development of small and medium C/C ++ systems; in addition to the basic C/C ++ syntax and data structure of the second stage, you can also learn some special data structures (B-tree/rb-tree/skiplist/lsm-tree/trie-tree) to meet your needs in special work. in terms of system programming, be familiar with multi-process and multi-thread programming. in the multi-process scenario, we will learn about the communication modes among most of the multi-process processes, and be able to flexibly select the communication modes (shared memory, semaphores, and pipelines ); multi-thread programming can effectively solve lock conflicts, develop and debug multi-threaded programs, and be familiar with network programming, understand the differences and selection of multi-process models, multi-thread models, and asynchronous network I/O models. be familiar with the principles and differences of different asynchronous network I/O models (select/poll/epoll/iocp ), familiar with common asynchronous frameworks (ACE/ICE/libev/libevent/libuv/Boost. ASIO, etc.) and use, if you are idle You can also look at some self-developed libraries (such as muduo) in China. you can also design a high-concurrency program architecture (such as leader-follow/master-worker ); measure the test taker's understanding about most of the problems in C/C ++ backend Server development (memory management, log printing, high concurrency, frontend and backend communication protocols, and service monitoring ), understand the RPC communication problems of various backend services (struct/http/thirft/protobuf, etc.); be familiar with using GCC and GDB to develop compilation and debugging programs, after the core of the online program is lost, it can quickly trace and solve the problem. in terms of general module development, you can accumulate or develop some common tools or libraries (such as asynchronous network framework, logstore, memory pool, thread pool, etc.). However, you should be cautious when using the tools or libraries after development, provincial traps to catch bugs.
8. language learning in other fields
It has a basic accumulation in the basic PHP/C ++ language. it is recommended that you try to learn different programming languages and look at your hobbies at the current stage, you can learn Python, Ruby, and other script languages. for functional programming languages, try Lisp, Haskell, Scala, and Erlang. for static languages, try Java or Golang, data statistics and analysis can help you understand the R language. if you want to use backend services from another perspective, try Node. js also includes Nginx_Lua, which is used with Nginx. To learn different languages, you can improve your horizons and solve the problems. for example, you can learn about the lightweight coroutine in addition to processes/threads. for example, in cross-machine communication scenarios, the Erlang solution is simple and amazing. for example, if you don't want to select C/C ++, there are also highly efficient Erlang/Golang availability and so on. The main purpose is to improve your vision.
9. other majors
In this phase, apart from the basic LNMP skills, some other fields of knowledge will be considered for learning. these are all possible, depending on personal interests and long-term objectives. Currently, many fields can be selected, such as cloud computing (distributed storage, distributed computing, virtual machines, etc.), Machine Learning (data mining, pattern recognition, etc, applied to statistics and personalized recommendations, natural language processing (Chinese word segmentation, etc.), search engine technology, graphic images, speech recognition, and so on. In addition to these high-performance systems, there are also many engineering aspects to learn from, such as high-performance systems, mobile development (Android/IOS), computer security, embedded systems, and hardware.
10. system design
On the basis of the second stage, the system design is able to apply the experience and skills it has mastered and design complicated medium and large systems, which can solve various online complex system problems, complete similar browser-> CDN-> server load balancer-> access layer-> Nginx + PHP-> service cache-> database-> various complex backend RPC interactions (storage backend, logical backend, anti-cheating) backend and external services) -> more complex backend services with soy sauce; support normal development and maintenance of websites with tens of millions to hundreds of millions of traffic per day.
Finally, I will share 10 tips on PHP performance optimization to help you better use PHP development:
1. foreach is more efficient. use foreach instead of the while and for loops.
2. do not declare variables inside the loop, especially variables such as objects.
3. if possible, the longest cycle should be placed on the inner layer, and the shortest cycle should be placed on the outer layer, so as to reduce the number of cross-cycle cpu layers and optimize program performance.
4. use single quotes instead of double quotes to reference strings to optimize PHP performance
5. replace I = I + 1 with I + = 1. Meets the c/c ++ habits and is highly efficient.
6. optimize Select SQL statements and perform Insert and Update operations as little as possible to optimize PHP performance.
7. perform as few file operations as possible, although PHP file operations are not efficient.
8. use PHP internal functions as much as possible
9. do not use regular expressions when you can use PHP internal strings to operate functions.
10. feof, fgets, and fopen. when file_get_contents can be used to replace the file and series methods, file_get_contents should be used as much as possible because of its high efficiency. Note the PHP version of file_get_contents when opening a URL file.