2019 PHP latest interview questions (with answers)

1. Database design experience, why divide the table? Sub-libraries? How much data is generally beginning in the table? Sub-libraries? The purpose of sub-library sub-table? What is a database vertical split? Split level? Partitions etc.

A: Why did you watch

When a table of data to reach the millions, query time you spent time becomes much, if there is a union query, then there might have died there. The purpose of the score sheet in this, reduce the burden of the database, shorten the query time. Daily development we often encounter the case of large tables, table refers to the so-called big stores table one million pieces or even ten million records. This table is too large, resulting in time-consuming database query time is too long and the insertion of poor performance, if the situation involves the joint inquiry, the performance will be worse. The purpose of sub-tables and table partitioning is to reduce the burden of database and improve the efficiency of the database, usually in terms of points is to improve the efficiency of CRUD table. The amount of data in the database is not necessarily controllable, in the case without sub-library sub-table, with the development time and business library table will be more and more, the amount of data in the table will be increasingly the larger, accordingly, data manipulation, CRUD overhead will be growing; in addition, because not distributed deployment, and a server resources (CPU, disk, memory, IO, etc.) is limited the amount of data can carry the final database, data processing capability will be bottlenecks.

II: sub-program table

1, do mysql cluster, someone will ask mysql cluster, the root partition table have anything to do? While on the score sheet it is not practical significance, but it is open to the role of the points table, what is the meaning of the cluster it? Reduce the burden to a database, it means reducing the number of sql sql queue queuing, for example: There are 10 sql request, if placed in a database server queue queue, he has to wait a very long time, if this 10 sql request, assigned to the queue line up five of the database server, a database server queue, only two, so the waiting time is not greatly shorten it?

linux mysql proxy installation, configuration, and separate read and write

mysql replication mutual master-slave configuration and installation, and data synchronization

Advantages: scalability, no complex operation (php code) of the plurality of sub-table

Disadvantages: the amount of data in a single table is not changed, the time spent in one operation, or so many large hardware overhead.

2. The vertical division is divided by field. Split level. It is divided by record

2. Database optimization What? What is the difference need to pay attention?

SQL optimization principles are: the need to read the first operand BLOCK minimize that maximum data throughput in the shortest possible time.

Adjustment bad SQL can usually cut from the following:

Check the bad SQL, to consider whether the wording as well as to optimize content

Check the SQL subquery to consider whether sub-queries can be re-written in a simple way connected

Check the optimized use the index

Consider the database optimizer

Avoid SELECT * FROM table statement appears to clear the isolated field.

In a SQL statement, more if a filter condition where the database records, more accurate positioning, where the conditions should be more forward.

Use the index as much as possible to cover the query. I.e., the SELECT fields to establish a composite index, index scan only when this query, block data are not read.

In determining whether the recording is recommended meet the conditions do not use SELECT COUNT () and select top 1 statement.

Use layer defining principle, spelling SQL statement, query decomposition, classification, and possible most layer is defined in the SQL statement, in order to reduce the processing amount data.

It should be absolutely avoided in order by clause to use an expression.

If you need to read data from the association table, the associated tables are normally not more than seven.

Use Caution IN and OR, In should be noted that the amount of data collection. Data collection is recommended not more than 200.

<> With <,> replaced> with> = replaced <substituting <=, this can effectively use the index.

When the reading of the query to minimize redundant data includes redundant columns and redundant rows.

For composite indexes to be noted that, for example, when establishing the composite column index order are F1, F2, F3, or where in the order consistent with the order of the fields to be indexed by the time of the order of these fields appear clause, and must contain a first a row. Only F1 or F1, F2 or F1, F2, F3. Otherwise it will not use the index.

Multi-table associated with the query, the following principles must be written, this is conducive to the establishment of an index to improve query efficiency. The following format

select sum (table1.je) from table1 table1, table2 table2, table3 table3 where (table1 conditions equivalent to (=)) and (the condition of non-equivalence of table1) and (table1 and table2 the link condition) and (table2 like value condition) and (table2 condition of non-equivalence) and (table3 and associated conditions in table2) and (condition equivalent of table3) and (table3 condition of non-equivalence).

Note: from behind the table in order of appearance of influence on the efficiency of research yet to be when on multi-table queries.

Subquery problem. For the functional connection can view or manner, do not use sub-queries

In the WHERE clause, to avoid a column four operations, especially where the condition of the left, prohibited the use of the arithmetic processing function of the column. For example, in some places like substring you can use instead.

If there is not in (in) operations in the statement, you should consider not exists (exists) to rewrite, the best way is to use an outer join to achieve.

Processing of a business process, you should make the time between the start and end of things interval as short as possible, in principle, do read the database in the previous completion of the write operation after the completion of the database to avoid cross.

Be careful not to use the column function and order by, group by, etc. for more columns, use caution disti software development t.

All union with the union in place, union perform database operations, perform a query to first ends of the respective union, which is in a temporary table, and then subjected to the sorting, filtering duplicate records.

When the business logic decides known no duplicate records and query A query B, the union should be used instead of All union, to improve the efficiency of the query.

20, select the most appropriate field properties, MySQL can be a good support large amounts of data access, but generally speaking, the smaller tables in the database, perform queries on it also will be faster. Therefore, when creating the table, in order to obtain better performance, we can set the width of columns in the table as small as possible.

For example, when defining the code of this field, if it is set to CHAR (255), it adds to the database apparently unnecessary space, and even the use of this type VARCHAR is superfluous, because the CHAR (6) can be very good complete the task. Likewise, if possible, we should use MEDIUMINT instead BIGIN to define integer field.

Another approach is to improve efficiency in where possible, try to keep the field is set to NOTNULL, this time to execute the query, the database do not have to compare the NULL values ​​in the future.

For some text fields, such as "provinces" or "gender", we can define them as ENUM type. Because in MySQL, the ENUM type is treated as numeric data, numeric data and much faster rate than it is processed text type. In this way, we can improve database performance.

Which cache 3. web development experience? Respectively, how to optimize?

Browser cache

On any modern browser (such as IE, FireFox, Chrome) toss Clear Private Data dialog box, you will probably notice the "Cache" This setting item.

Proxy Cache

Web proxy cache server uses the same principle, but on a larger scale. Acting in the same way to serve millions of users, large companies and ISP often in their firewall or a separate device (also known as intermediary (intermediaries)) to set up the proxy cache.

Gateway caches

Also known as "reverse proxy cache" or "alternate cache." Gateway cache also plays an intermediary role, but not a network administrator to deploy, but mostly webmasters (specializes in the operation and maintenance engineer, or a person or set of programs UED Add) deployment, it is easier to extend and maintain.

4. Give your memory, 10G count the number of times each keyword appears in the file 256M of how to achieve?


 

Thinking

$handle=fopen("/tmp/uploadfile.txt","r")ordie("Couldn't get handle");if($handle){while(!feof($handle)){$buffer=fgets($handle,4096);// Process buffer here..}fclose($handle);}

5. PHP life cycle / start process

The complete life cycle of the module initialization, the initialization request, the request processing request to close the module to close five stages.

Under cli mode, the full implementation of the above script will each stage five; for fastcgi mode, only when it starts execution module initialization, after initialization requests are gone requests, process requests, request to close three stages, in fastcgi module to perform closed closing stages. Each extension of load modules is done in the initialization phase.

6. talk about the PHP (memory) garbage collection

Each variable corresponds zval a data structure, val and a structure within the structure, the structure body has a reference count (PHP7 terms, for PHP5, this reference count is stored in the zval structure), the object identifier reference number of zero indicates the object when the object reference count may be recovered.

refcount reduce time objects: modify the variable, the function returns (release local variables), unset variables

For arrays and objects, there may be variable citations member variable itself, which is a circular reference, this will result in the variable memory will never be recovered, and become garbage.

PHP in this case gives a garbage collection mechanism: If the reference to the array, and object count reduction is not zero, it is considered that they may be garbage, put them in the garbage collector. And other garbage collector to a certain number Thereafter, the waste: all possible waste refcount is decremented by 1, if it is 1, indicating garbage, memory recall is performed; if not 1, indicating that there are other variables in use, refcount plus 1 again; this object reuse and garbage collection is also reflected in other languages: redis also uses the reference count represents the number of references for each object.

7. PHP7 the difference with PHP5

Improved performance - the code into PHPNG PHP7, the velocity is twice the PHP 5.

Reduce memory consumption - the optimization of PHP 7 using fewer resources.

Scalar type declarations - can now enforce parameters and return types.

Consistent 64-bit support - unanimous support for 64-bit architecture of the machine.

Improved abnormal level - abnormal level has been improved

Many fatal error converted to an exception - an exception to increase the scope, covering many fatal error converted to an exception.

Secure random number generator - add a new secure random number generator API.

Deprecated SAPI deleted and extended - a variety of old and unsupported SAPI and extension removed from the latest version.

Null coalescing operator (?) - add a new empty coalescing operator.

Return and scalar type declaration - support the added return type and parameter types.

Anonymous category - support anonymous added.

Zero cost assert - support assertions zero cost increase.

8. MongoDB scenarios

mongodb support replica set, index, automatic sheet can ensure high performance and availability.

Higher write load

By default, MongoDB is more focused on high data write performance, not transaction-safe, MongoDB is suitable for business systems have a large number of scenes "low-value" data. But it should avoid the use of MongoDB in the security system of high transaction, unless the transaction from architecture designed to ensure safety.

High Availability

MongoDB complex sub-set (Master-Slave) configuration is very simple and convenient, in addition, a single node failure processing MongoDB respond quickly automatically secure complete failover. These properties can be such that in a relatively unstable MongoDB (clouds host) environment, maintaining high availability.

Large amounts of data or in the future will become very large

Rely on their own characteristic database (MySQL), to complete the extension data is more difficult, in MySQL, when a single-up table to 5-10GB significant performance degradation will occur, this time need by the horizontal and vertical split data hours to complete the split library extensions, by means of a drive usually requires using MySQL agent layer or layers to complete this kind of demand. The characteristics of a variety of built-in MongoDB data slice, can be well adapted to the needs of large amounts of data.

Location-based data query

MongoDB supports two-dimensional spatial indexing, so you can quickly and accurately obtain data from the specified location.

Table structure is not clear

In some traditional RDBMS, add a field will lock the entire database / table, when the execution request or a heavy load will cause significant degradation of the performance of other requests. Typically occurs when the data table is larger than 1G (even more when more than 1TB). Because MongoDB is a document database, document structure for non-cargo add a new field is a very fast operation, and will not affect the existing data. Another benefit when the service data is changed, is not need to modify the table structure by the DBA.

9. PHP SMS codes anti brush mechanism

1, Time Limit: 60 seconds to send again

Start codes from the transmission, the front end (client) will be a 60-second countdown within this minute, the user can not submit a request to send information to a plurality of times. Although this method use was more common, but it is not very useful, people are a little better technology can circumvent this limitation, send SMS verification code directly.

2, phone number restriction: a single phone number, can not exceed 24 hours 5

When used for the same phone number registered send SMS or other verification operation code, the system can limit the phone number, e.g., 24 hours 5 can only send SMS codes, error exceeds the limit is performed (eg: System busy, please try again) later. However, this is only possible to avoid doing so manually brush SMS only, for the bulk machine uses a different mobile number to brush messages, this method is also helpless.

3, short codes limits: transmitting the same codes within 30 minutes

Online there is a way to say: within 30 minutes, all requests, SMS verification code is sent with a verification code. The first request message interfaces, message authentication code results and cache, requested again within 30 minutes, the process directly returns the cached content. For in this way, is not very clear message interfaces Chamber of Commerce will not be charged for sending cached information, if interested can learn to understand.

4, front and rear ends calibration: calibration parameters submitted Token

In this way less people say, personally I feel that this approach may be worth a try. Front-end (client) at the time of the request to send text messages, submit a Token parameter to the server, the server on the Token parameter checking, after verification by, again requested to send text messages to send text messages to the user interface of the mobile phone.

5, the only restrictions: micro-channel product, limiting the number of the same micro-channel user's request ID

If the product is a micro-channel, it can be identified through the micro channel ID, then the same restrictions on the user ID of a micro channel, a maximum amount of message can be transmitted within 24 hours.

6, product flow restrictions: out step by step

For example, after registering a verification code SMS usage scenarios, we will register step into two steps, users enter the phone number and the password is set, the next step before entering the verification step verification codes.

7, the graphic codes limits: Graphics Interface verified before requesting

A user input through the graphical codes and then, re-request message interface to obtain verification code. In order to have a better user experience, can also be designed to: a beginning not need to enter a verification code graphics, after the operation reaches a certain amount, only need to enter the Captcha code. Specific situation, please be designed according to specific scenarios.

8, IP and Cookie restriction: Restrict the same maximum number of IP / Cookie Information

Cookie or using the IP, a user can easily identify the same, and then to be limiting (eg: up to 20 messages can only be sent within 24 hours) the same user. However, Cookie able to clean up, can simulate IP, and IP will appear in the same situation LAN IP, and therefore, when using this method, you should think in terms of specific circumstances.

9, SMS early warning mechanism, good protection after problems

The above method does not necessarily completely eliminate SMS brush, therefore, we should also do SMS early warning mechanism, that is, when the amount of text messages after a certain amount, send warning message to the administrator, the administrator can immediately for SMS Interface to monitor the situation and protection.

10. How to design a highly concurrent systems

① optimization of the database, including reasonable transaction isolation level, SQL statement optimization, optimization index

② use caching to minimize database IO

③ distributed database, distributed cache

④ server load balancing

11. PHP Inversion of Control (IOC) and dependency injection (DI) Concept

IOC (inversion of control) Control inversion mode; inversion control is mentioned dependencies between components external from the internal program management;

DI (dependency injection) dependency injection mode; Dependency injection refers to the injection assembly dependency or otherwise by an external parameter;

12. mySQL there 2000w data, only the data stored in redis 20w, how to ensure that the data is hot data in redis

Knowledge: redis-memory data set size up to a certain size and they will perform data elimination strategy (exit strategy). redis offers six data out of the policy:

volatile-lru: selection of the least recently used data out of the set of data set expiration time (server.db [i] .expires) in

volatile-ttl: selection of data to be expired expiration time has been set out from the data set (server.db [i] .expires) in

volatile-random: the expiration time has been set from the data set (server.db [i] .expires) arbitrarily selected out of the data

allkeys-lru: selection of the least recently used data out from the data set (server.db [i] .dict) in

allkeys-random: selecting out data from the data set (server.db [i] .dict) any

no-enviction (expulsion): prohibits the expulsion data

 

Finally, I wish you all the way through the interview, get your favorite offer.

 

Guess you like

Origin www.cnblogs.com/a609251438/p/11892705.html