Home >Backend Development >PHP Tutorial >The best and most practical PHP secondary development tutorial_PHP tutorial

The best and most practical PHP secondary development tutorial_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:14:542036browse

 

Secondary development, simply put, is to customize and modify existing software, expand functions, and then achieve the functions and effects you want. Generally speaking, the core of the original system will not be changed.

 

With the continuous development of information technology, a series of excellent open source works have emerged in the IT industry, and their authors are either individuals, project teams, or software companies. Selecting and applying these excellent open source software, and carrying out secondary development that meets business needs on this basis, will not only save information costs (time costs and development costs) for enterprises, but also provide technical guarantees. This is what we often hear: stand on the shoulders of giants and you will see further. Therefore, many domestic companies need secondary development talents.

 

4. Introduction

Secondary development is not just development, but more importantly, absorbing the essence, summing up experience, straightening out ideas, avoiding detours, and improving yourself.

Standing on the shoulders of giants, you will see further! ! !   In order to let more people understand the secondary development and understand the secondary development of DedeCMS more conveniently, the following will briefly introduce some basics and outlines about the secondary development of DedeCMS  

 

Directory structure summary:

· DedeCMS file structure analysis. Familiar with the basic functions of each file to facilitate modifications. After knowing the general function of each file, you can easily modify the files File structure summary:
· DedeCMS database structure analysis, at least be familiar with the function of each table, understand the design of several core tables and the meaning of the fields, so that you can quickly judge whether to add new requirements after getting new requirements. fields, or create a new table to process. At the same time, you can also understand the database design ideas of DedeCMS and add useful design ideas to your own system. · DedeCMS process control and analysis of some core files. Familiar with some common process controls such as login, registration, document management, permission control, classification management, model setting, etc. Dissect several core files to understand their programming techniques and security mechanisms · Development of DedeCMS plug-ins (**** plug-ins and embedded plug-ins) Familiar with the writing of two plug-ins, the import and export of plug-ins, and the use of plug-in matching models   In recent years, with the development of the Internet, e-commerce has also grown along with it, and B2B, C2C, and B2C e-commerce models have also continued to mature. At this time, many e-commerce related PHP open source products were born. In terms of B2C, there are well-known products at home and abroad such as Ecshop, Zencart, Magento, etc. Let’s briefly introduce the process of learning Ecshop secondary development and some things to pay attention to:  

 

· Ecshop template replacement. Familiar with the use of the streamlined version of Smarty, embedding your own interface, and Ecshop template replacement skills · Ecshop secondary development example: Chinese and English switching function, flash sale function, production of JD.com templates, etc. Learning purpose:

Analysis of common PHP caching technologies [Concept version]

In most cases our website will use a database as a container for site data storage. When you execute a SQL query, the typical process is: connect to the database -> prepare the SQL query - > send the query to the database - > get the results returned by the database - > close the database connection. However, some data in the database is completely static or changes infrequently. The caching system will cache the results of SQL queries to a faster storage system to avoid frequent database operations and greatly improve program execution. time, and caching query results also allows you to process them later.

 

 

The data cache mentioned here refers to the database query cache. Every time you access a page, it will first detect whether the corresponding cached data exists. If it does not exist, connect to the database, obtain the data, and serialize the query results. Save it to a file, and the same query results will be obtained directly from the cache file in the future.

 

Every time you visit a page, it will first detect whether the corresponding cached page file exists. If it does not exist, connect to the database, get the data, display the page and generate the cached page file at the same time, so that the page file will be the same the next time you visit. It worked. (Template engines and some common cache classes on the Internet usually have this function)

 

I won’t introduce it here, it is not what this article will discuss, I will just briefly mention it:

Memcached is a high-performance, distributed memory object caching system used to reduce database load and improve access speed in dynamic applications.

dbcached is a distributed key-value database memory cache system based on Memcached and NMDB.

Although the above caching technology can well solve the problem of frequent database queries, its disadvantage is that the data is not timely. Here I give the methods I commonly use in projects:

 

Check whether the file exists and the timestamp is less than the set expiration time. If the file modification timestamp is greater than the current timestamp minus the expiration timestamp, then use the cache, otherwise update the cache.

Don’t judge whether the data needs to be updated within the set time, and update the cache after the set time. The above is only suitable for use when timeliness requirements are not high, otherwise please see below.

 

When data is inserted or updated, the cache is forced to be updated.

Here we can see that when a large amount of data needs to be updated frequently, disk read and write operations will eventually be involved. How to solve it? In my daily projects, I usually do not cache all the content, but cache some content that does not change frequently to solve the problem. But in the case of heavy load, it is best to use shared memory as a cache system.

At this point, PHP caching may be a solution, but its disadvantage is that because each request still needs to be parsed by PHP, the efficiency problem is still more serious under heavy load. In this case, you may use to the static cache.

 

The static cache mentioned here refers to HTML cache. HTML cache generally does not need to determine whether the data needs to be updated, because usually when HTML is used, it is usually a page whose content does not change frequently. When the data is updated, just force the HTML to be updated.

In fact, a caching system involves a lot of problems. I will only introduce my usual caching ideas here, and I will not introduce the use of software to implement caching and write specific codes.

If you have any good solutions, please submit them below and let us discuss them together.

Use exec, system and other functions to call system commands in php

PHP’s built-in functions exec and system can call system commands (shell commands), and of course there are functions such as passthru and escapeshellcmd.

In many cases, using PHP’s exec, system and other functions to call system commands can help us complete our work better and faster. For example, exec helped me a lot when I was batch processing .rar files two days ago.

Today I will sort out the commonly used calling system functions and share my experience with everyone.

Note: If you want to use these two functions, the safe mode in php.ini must be turned off, otherwise PHP will not allow you to call system commands for security reasons.

Let’s first look at the explanation of these two functions in the PHP manual:

exec --- Execute external program

Syntax: string exec (string command [, array &output [, int &return_var]] )

Description:

exec( ) executes the given command command, but it does not output anything. It simply returns the last line from the result of the command. If you need to execute a command and get all the information from the command , you can use the passthru() function.

If the parameter array is given, the specified array will be filled with each line output by the command. Note: If the array already contains some elements, exec() will append it to the end of the array. If you don't want this function to append elements, you can call unset() before passing the array to exec().

If the parameters array and return_var are given, the status command returned to execution will be written to this variable.

Note: If you allow data from user input to be passed to this function, then you should use escapeshellcmd( ) to ensure that the user cannot trick the system into executing arbitrary commands.

Note: If you use this function to start a program and want to leave it while executing in the background, you must make sure that the output of the program is redirected to a file or some output data. stream, otherwise PHP will hang until the program execution ends.

System --- Execute external programs and display output

Syntax: string system (string command [, int &return_var])

Description:

System( ) executes the given command command and outputs the result. If the parameter return_var is given, the status code of the executed command will be written to this variable.

Note: If you allow data from user input to be passed to this function, then you should use escapeshellcmd( ) to ensure that the user cannot trick the system into executing arbitrary commands.

Note: If you use this function to start a program and want to leave it while executing in the background, you must make sure that the output of the program is redirected to a file or some output data. stream, otherwise PHP will hang until the program execution ends.

If PHP is running as a server module, system( ) will try to automatically clear the web server's output buffer after outputting each line.

Returns the last line of the command if successful, false if failed.

If you need to execute a command and get all the data from the command, you can use the passthru() function.

These two are used to call system shell commands,

Exec can return all execution results to the $output function (array). $status is the status of the execution. 0 means success and 1 means failure

Systerm does not need to provide the $output function. It returns the result directly. Similarly, $return_var is the execution status code. 0 is success and 1 is failure

The biggest success of open source comes from the Web

The open source movement is wildly popular and has made a mark in the history of software development. But where is its most profound impact? What is the most successful open source "project" in history?

In fact, overall, isn’t the Web the biggest success of the open source movement?

Perhaps the most famous example is LAMP behind many websites in hidden domains, which are Linux, Apache, MySQL and PHP. But when you think about it, you'll find more.

Listed below are some of the open source projects that make the Web work.

In the web browser market, although Microsoft's closed source software IE browser still occupies a large share, other open source projects with similar functions have become popular and are growing. Like Mozilla's Firefox browser (it is open source, as well as Flock and PaleMoon). There are also rapidly growing Webkit-based browsers, like Safari, but the most famous is Chrome.

If you include mobile networks, Webkit dominates the browsers in iPhone, Android and Blackberry mobile phones.

To date, Apache is the most widely used network server software and it is open source, but a lightweight server software called Nginx has become popular in recent years. In fact, two of the top three web server software are open source (the exception is Microsoft's IIS, which ranks second, but it is far from first).

In addition, a large number of server-side underlying software are also open source. For example, many high-traffic websites use Varnish as the caching layer between website visitors and Memcached as the caching layer between the website database. These are just two of many examples.

Most of the programming and scripting languages ​​used on the Internet are open source, such as PHP, Perl, Python, Ruby, etc.

However, few websites are built from scratch. It is no exaggeration to say that there are hundreds of open source content management systems (CMS) and web frameworks to assist developers, such as WordPress, Drupal, Ruby on Rails, Django, Joomla, DedeCMS, Ecshop, etc.

The open source software MySQL is by far the most popular website database, but there are other open source software with similar functions, such as PostgreSQL, not to mention the many "non-relational (NoSQL)" databases that have appeared recently.

Now that we’re talking about underlying software, we have to mention the underlying systems that we rely on every time we use the Internet or anything on the Internet:

The Web (for that matter the entire Internet) is nothing without the domain name resolution system. As we all know, domain name resolution systems allow users to use domain names like example.com instead of IP addresses. BIND is pretty much the de facto standard for DNS server (aka name server) software, and, as you may have guessed by now, it's open source.

All websites must run on a server, and that's where open source reigns. Although Windows dominates the desktop space, most of the servers that websites run on use the open source Linux operating system. Other popular choices are freeBSD and OpenBSD.

Because in many cases, open source software can provide the same performance as commercial closed source software and is free, it is not surprising that open source software is so popular. Free is a hard price to beat.

If the Web didn't run on all this free software, it would probably have a hard time getting widely accepted.

Note that we didn’t say there isn’t any closed source software on the Web, which obviously does exist. However, statistically speaking, the real exception to the dominance of Web open source is Microsoft's Windows-based series of systems.

Beyond that, you usually have to dig deeper to discover more private closed source technologies, like the operating systems on routers and similar devices. But that's the Internet, not the Web.

Thanks to the rise of the Internet, easy communication, and collaboration and sharing in the 1980s, the open source movement flourished. In the 1990s, when the Web was born on top of Internet infrastructure, the open source movement was ready to help.

No one can deny that open source rules much of the web. Open source and the Web have a cooperative and symbiotic relationship, mutual benefit and win-win cooperation. That's why we believe the Web is arguably open source's biggest success to date. (We do not mean to deny Tim Berners-Lee. Note: Tim Berners-Lee, the father of the World Wide Web and the first webmaster

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440260.htmlTechArticleSecondary development, simply put, is to customize and modify existing software, expand functions, and then achieve Generally speaking, the functions and effects you want will not change the content of the original system...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn