PHP advanced interview questions sharing

小云云
Release: 2023-03-20 14:40:01
Original
1936 people have browsed it

I have interviewed several companies recently. I have recorded some important questions to urge myself to learn and improve. There is a lot of content. I will improve it bit by bit and learn step by step. I also hope Give your friends some help.

1. mysql related knowledge
1. Mysql optimization methods
MYSQL optimization common methods
Mysql performance optimization plan
2. How to divide the database Table splitting
3. How to do dual-machine hot backup and load balancing with Mysql+
4. What are the data table types
MyISAM, InnoDB, HEAP, BOB, ARCHIVE, CSV, etc.
MyISAM: Mature, stable, easy to manage, and fast to read. Some functions do not support (transactions, etc.), table-level locks.
      InnoDB: Supports transactions, foreign keys and other features, and data row locking. It takes up a lot of space and does not support full-text indexing, etc.
The main features of myisam and Innodb engines
What is the difference between MySQL's storage engine MyISAM and InnoDB?
5. Prevent sql injection method
mysql_escape_string(strip_tags($arr["$val"])) ;

    ##
    /**
    * 函数名称:post_check() 
    * 函数作用:对提交的编辑内容进行处理 
    * 参  数:$post: 要提交的内容 
    * 返 回 值:$post: 返回过滤后的内容 
    */
    function post_check($post){
    if(!get_magic_quotes_gpc()){// 判断magic_quotes_gpc是否为打开 
    $post =addslashes($post);// 进行magic_quotes_gpc没有打开的情况对提交数据的过滤 
    }
    $post =str_replace("_","\_",$post);// 把 '_'过滤掉
    $post =str_replace("%","\%",$post);// 把 '%'过滤掉
    $post = nl2br($post);// 回车转换 
    $post =htmlspecialchars($post);// html标记转换 
    return $post;
    }
    Copy after login
6. mysql After splitting a large table into multiple tables, how to solve the problem of cross-table query efficiency

7. Index application
When to consider an index
When is it not suitable for an index
Whether a statement uses an index How to judge
Frequently occurring scenarios where indexing is not needed:
like '%.....'
                                                                        out to use index's ’ s             ’’s ’ through out's ‐ ‐‐ ‐‐‐‐ together through‐through to the next page to be used,         ‐                                                       using   using using using using           through using         through out through through out Through out through out through through off ‐ ‐ ‐‐‐‐‐ to :
It can only be used for MYIsAM tables and is created on CHAR, VARCHAR, and TEXT type columns.


8. How to optimize mysql for large tables (tens of millions)?
9. Mysql’s slow query problem

In fact, analyzing through slow query logs is a comparison The simple way is, if you don’t want to read the logs, you can use tools to complete it,


such as mysqldumpslow, mysqlsla, myprofi, mysql-explain-slow-log, mysqllogfilter, etc. I feel that it requires rich experience to analyze it by myself. waste time.

10. Regarding saving session in user login status, the advantages and disadvantages of cookie or database or memcache http://www.dewen.org/q/11504/

About saving session% in user login status 2Cookie or database or memcache? 11. Handling extreme situations in transaction applications -INSERT,UPDATE,DELETE

DQL-SELECT

DCL--GRANT,REVOKE,COMMIT,ROLLBACK

2. PHP basics

  • Cross-domain sharing of session

  • ## Several ways and differences in how PHP connects to mysql database

    mysql :Process-oriented
    mysqli:Object-oriented
    pdo:High portability
    Please refer to: PHP Basic Series: Three APIs used by PHP to connect to the MySQL database

    3. PHP advanced

    • The use of long and short connections

    • socket Use

    • Payment security issues


    • Object-oriented

      Three major features: encapsulation, inheritance, polymorphism (method rewriting ).
      Abstract class: abstract, at least one method is an abstract method and cannot be instantiated, defining a public interface for subclasses.
      Interface: interface, solves the single inheritance problem of PHP. All methods are abstract methods with public access rights. Variables cannot be declared and only constants can be declared.
      Inherit a class and implement multiple interfaces at the same time
      class A extends B implements interface 1, interface 2..., interface n(){
      //Implement the methods in all interfaces
      }

    • Analysis of the reasons for the performance difference between lamp and lnmp website architecture

    • Performance analysis of interpreted languages ​​and compiled languages, with examples.

      4. Regular rules

      Email, html, js, etc. matching

      5. Development basics

      • Process and thread definitions, differences and connections.

        Process status: running, ready, waiting

      6. Nosql database


      Contact the difference between memcached, redis and mongodb
      3 completely different scenes. 1.memcached: a single key-value pair memory cache, an irreplaceable distributed cache for object caching; 2.redis: a collection of algorithms and data structures, fast data structure operations is its biggest feature, and supports data persistence ; 3. Mongodb is a bson structure, between rdb and nosql, which is looser and more flexible, but does not support transactions and is only used for non-important data storage.
      Reference Can MongoDB or redis replace memcached?
      7. Commonly used Linux commands
      For example, soft links
      8. Architecture related

      • Pressure before the project goes online Test, the number of concurrencies supported by a single server, and the number of pvs.

      • Reasonable allocation of server resources

      CPU: Apache

      MySQL is in a high load environment, and there are too many disk IO reads and writes. It will definitely take up a lot of resources and the CPU usage will definitely be too high.
      memory: memory library, database software
      hard disk: file

      • Web2.0 architecture selection

                                                                      ‐                                                                                                                                                         that MongoDB+redis or MySQL+Memcached are better combinations. If the logic is simple, use NOSQL. , LLMP

      There is also a LNAMP architecture on the Internet, which combines the advantages of nginx and Apache. Apache is used to load PHP. nginx is responsible for parsing other Web requests and uses the rewrite module of nginx. However, the Apache port is not open to the outside world. Apache Many modules can be loaded without reducing resources.


      • Others:

      • Data mining experience, familiar with hadoop/lucene/mahout;

      Nothing to do, got it done Some answers. . . It may not be comprehensive, so I’ll save it for later.

      1. Basic knowledge points

      1.1 The meanings of several status codes in the HTTP protocol: 503 500 401 403 404 200 301 302. . . 200: The request is successful and the requested data is returned. 301 : Permanent redirect.

      302: Temporary line redirection.

      401: The current request requires user authentication.
      403: The server refuses to execute the request, that is, it does not have permission.
      404: The request failed, the requested data was not found on the server.
      500 : Server error. General server-side program execution errors.
      503: The server is temporarily under maintenance or overloaded. This state is temporary.

      1.2 Include require include_once The difference between require_once.
      Handling failure is different:
      When require fails, a fatal level error will be generated and the program will stop running. When
      include fails, only a warning level error is generated and the program continues to run.

      include_once/require_once handles errors in the same way as include/require.
      The only difference is that when the included file code already exists, it is no longer included.

      1.3 The evolutionary history of several versions of PHP/Mysql, such as major improvements from mysql4.0 to 4.1, PHP 4.x to 5.1, etc.

      1.4 HEREDOC introduces
      A method of defining strings.

      Structure:

      <<<. After the prompt, define an identifier (on a separate line),

      and then a new line. Next is the string itself,

      Finally, use the previously defined identifier as the end mark (a separate line)
      Note:
      The naming of the identifier must also comply with PHP rules like other tags:
      Can only contain letters, numbers and underscores, and must start with letters and underscores

      1.5 Write some PHP magic (skill) methods;
      __construct() is automatically called when instantiating a class.
      __destruct() is automatically called when the class object is used.
      __set() is called when assigning a value to an undefined property.

      __get() is called when undefined attributes are called.

      __isset() Will be called when using isset() or empty() function.
      __unset() Will be called when using unset().
      __sleep() is called when serializing using serialize.
      __wakeup() is called when deserializing using unserialize.
      __call() Called when calling a method that does not exist.
      __callStatic() calls a static method that does not exist.
      __toString() is called when converting an object into a string. Such as echo.
      __invoke() Called when trying to invoke an object as a method.
      __set_state() Called when using the var_export() function. Accepts an array parameter.
      __clone() Called when using clone to copy an object.

      1.6 Some configure parameters when compiling php
      –prefix=/usr/local/php php installation directory
      –with-config-file-path=/usr/local/php/etc Specify php.ini Location
      –with-mysql=/usr/local/mysql mysql installation directory, support for mysql
      –with-mysqli=/usr/local/mysql/bin/mysql_config mysqli file directory, optimization support
      –enable-safe-mode Turn on safe mode
      –enable-ftp Turn on support for ftp
      –enable-zip Turn on support for zip
      –with-bz2 Turn on support for bz2 files
      –with -jpeg-dir Turn on support for jpeg pictures
      –with-png-dir Turn on support for png pictures
      –with-freetype-dir Turn on support for freetype font libraries
      –without-iconv Turn off iconv Function, conversion between character sets
      –with-libxml-dir Open support for libxml2 library
      –with-xmlrpc Open c language for xml-rpc
      –with-zlib-dir Open support for zlib library
      –with-gd Open support for the gd library

      For more information, you can use ./configure help to view

      1.7 Three ways to pass parameters to php.

      Method one uses $argc $argv

      Method two uses getopt function ()

      Method three prompts the user for input and then gets the input parameters. A bit like C language

      1.8 (mysql) Please write the meaning of data type (int char varchar datetime text); What is the difference between varchar and char;
      int: Numeric type
      char: fixed-length string type
      varchar: variable-length string type
      datetime: period time type
      text: text type

      What is the difference between varchar and char:
      a . The length of char is fixed, no matter how much data you store, it will always have a fixed length.
      Varchar is of variable length, but it needs to add 1 character to the total length, which is used to store the position.

      b. char has a fixed length, so the processing speed is much faster than varchar, but it wastes storage space.
      So the storage is not large, but if you have speed requirements, you can use the char type, and vice versa. Can be instantiated with varchar type.

      1.9 Debugging functions such as error_reporting use the
      error_reporting() function to set the error_reporting directive in php.ini at runtime.
      So you can adjust the displayed error level at any time in the program.
      When using this function display_errors must be turned on.

      1.10 Have you ever used version control software? If so, what is the name of the version control software you used?

      1.11 The difference between posix and perl standard regular expressions;

      1.12 What areas are restricted after Safe_mode is turned on?
      Starting safe_mode will restrict many PHP functions, especially system-related file opening, command execution and other functions.
      All functions that operate files will only operate with Files with the same script UID.

      1.13 Write code to solve the problem of multiple processes/threads reading and writing a file at the same time.
      PHP does not support multi-threading. You can use PHP's flock locking function to achieve this.
      $fp = fopen("/tmp/lock.txt", "w+");
      if (flock($fp, LOCK_EX)) { // Perform exclusive locking
      fwrite($fp , "Write something here\n");
      flock($fp, LOCK_UN); // Release the lock
      } else {
      echo "Couldn't lock the file !";
      }
      fclose($fp);

      1.14 写一段上传文件的代码。
      upload.html

      <form enctype="multipart/form-data" method="POST" action="upload.php">
      Send this file: <input name="name" type="file" />
      <input type="submit" value="Send File" />
      </form>
      upload.php
      $uploads_dir = &#39;/uploads&#39;;
      foreach ($_FILES["error"] as $key => $error) {
      if ($error == UPLOAD_ERR_OK) {
      $tmp_name = $_FILES["tmp_name"][$key];
      $name = $_FILES["name"][$key];
      move_uploaded_file($tmp_name, "$uploads_dir/$name");
      }
      }
      Copy after login

      1.15 Mysql 的存储引擎,myisam和innodb的区别。
      a. MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持.
      b. MyISAM类型的表强调的是性能,其执行数度比InnoDB类型更快.
      c. InnoDB不支持FULLTEXT类型的索引.
      d. InnoDB 中不保存表的具体行数,也就是说,
      执行select count(*) from table时,InnoDB要扫描一遍整个表来计算有多少行,
      但是MyISAM只要简单的读出保存好的行数即可.
      e. 对于AUTO_INCREMENT类型的字段,InnoDB中必须包含只有该字段的索引,但是在MyISAM表中,可以和其他字段一起建立联合索引。
      f. DELETE FROM table时,InnoDB不会重新建立表,而是一行一行的删除。
      g. LOAD TABLE FROM MASTER操作对InnoDB是不起作用的,解决方法是首先把InnoDB表改成MyISAM表,导入数据后再改成InnoDB表,
      但是对于使用的额外的InnoDB特性(例如外键)的表不适用.
      h. MyISAM支持表锁,InnoDB支持行锁。

      二. web 架构,安全,项目经验
      2.1 介绍xdebug,apc,eAccelerator,Xcache,Zend opt的使用经验。

      2.2 使用mod_rewrite,在服务器上没有/archivers/567.html这个物理文件时,重定向到index.php?id=567 ,请先打开mod_rewrite.
      首先,打开mod_rewrite模块。

      其次,http.conf找到以下代码段:

      <Directory />
      Options FollowSymLinks
      AllowOverride None
      </Directory>
      Copy after login

      将其中的:AllowOverride None 改为 AllowOverride All ,重启httpd服务即可。

      然后,在项目根目录下简历 .htaccess 文件,填写规则。

      2.3 MySQL数据库作发布系统的存储,一天五万条以上的增量,预计运维三年,怎么优化?
      a. 设计良好的数据库结构,允许部分数据冗余,尽量避免join查询,提高效率。
      b. 选择合适的表字段数据类型和存储引擎,适当的添加索引。
      c. mysql库主从读写分离。
      d. 找规律分表,减少单表中的数据量提高查询速度。
      e。添加缓存机制,比如memcached,apc等。
      f. 不经常改动的页面,生成静态页面。
      g. 书写高效率的SQL。比如 SELECT * FROM TABEL 改为 SELECT field_1, field_2, field_3 FROM TABLE.

      2.4 写出一种排序算法(原理),并说出优化它的方法。

      2.5 请简单阐述您最得意的开发之作

      2.6 对于大流量的网站,您采用什么样的方法来解决各页面访问量统计问题
      a. 确认服务器是否能支撑当前访问量。
      b. 优化数据库访问。参考2.3
      c. 禁止外部访问链接(盗链), 比如图片盗链。
      d. 控制文件下载。
      e. 使用不同主机分流。
      f. 使用浏览统计软件,了解访问量,有针对性的进行优化。

      2.7 您是否用过模板引擎? 如果有您用的模板引擎的名字是?
      Smarty

      2.8 请介绍Session的原理,大型网站中Session方面应注意什么?

      2.9 测试php性能和mysql数据库性能的工具,和找出瓶颈的方法。

      2.10 Regularly propose all links in a web page.

      2.11 Introduce the principles of common SSO (single sign-on) solutions (such as dedecms integrating discuz's passport).

      2.12 What are the characteristics of the PHP framework you have written, what problems does it mainly solve, and how is it different from other frameworks.

      2.13 What are the differences in performance optimization between large forums/news article systems/SNS websites?

      2.14 Photo album applications: It is required to be able to select and upload multiple files at the same time in the browser. The image must be able to be cropped, and the compressed package must be decompressed on the server side. Can upload a single file up to 50M. A progress bar is displayed during the upload process. Thumbnails of four sizes can be generated for each picture, and the video files must be converted into flv for flash playback. Describe the various types of open source software to be covered and their simple uses.
      A group of monkeys line up in a circle and are numbered according to 1, 2,...,n. Then start counting from the 1st one, count to the mth one, kick it out of the circle, start counting from behind it, count to the mth one, kick it out..., and continue in this way until the end. Until there is only one monkey left, that monkey is called the king. Programming is required to simulate this process, input m, n, and output the number of the last king. Use a program to simulate this process.

      3. Basic use of unix/linux
      3.1 Some methods to view the current system load information under Linux.

      3.2 Basic shortcut keys for vim.

      3.3 SSH security enhancement method; configuration of password mode and rsa key mode.

      3.4 rpm/apt/yum/ports Basic commands for package installation, query, and deletion.

      3.5 The basic format of Makefile, gcc compilation and connection commands, the difference between -O0 and -O3.

      3.6 Basic use of gdb, strace, valgrind.

      4. Front-end, HTML, JS
      css box model.
      Prototype in javascript.
      The scope of this object in javascript.
      The difference between IE and firefox event bubbling.
      What are weird mode, standard mode, and near-standard mode.
      Definition of DTD
      Commonly used hacks for IE/firefox.
      firefox, the front-end js/css debugging tool under IE.

      5. How to understand the behavior in ThinkPHP 3.0 architecture three (core + behavior + driver)?
      Core + Behavior + Driver
      The official abbreviation of TP is: CBD
      This issue has been explained in detail in the TP manual. .
      Core: It is the core code of the framework, an indispensable thing. TP itself is a framework developed based on the MVC idea.
      Behavior: Behavior plays a decisive role in the architecture of the new version of ThinkPHP. On the core of the system, many tag extension bits are set, and each tag position can execute its own independent behavior in turn. This is how behavioral extensions were born, and many system functions are also completed through built-in behavioral extensions. All behavioral extensions are replaceable and additive, thus forming the basis for the assembly of the underlying framework.
      Driver: database driver, cache driver, tag library driver and template engine driver, as well as external class extensions.
      The best thing is to download a document and read it. Basically all the functions in TP will have very detailed descriptions and examples.

      Frame, that is, framework. In fact, it is a semi-finished product of a certain application, a set of components for you to choose and use to complete your own system. To put it simply, you use the stage set up by others and you perform. Moreover, frameworks are generally mature, continuously upgraded software.
      Why use a framework?

      Because software systems have developed to this day and have become very complex, especially server-side software, there are too many knowledge, contents, and problems involved in the design. Using other people's mature frameworks in some aspects is equivalent to asking others to help you complete some basic work. You only need to concentrate on completing the business logic design of the system. Moreover, the framework is generally mature and robust, and it can handle many detailed issues of the system, such as transaction processing, security, data flow control and other issues. In addition, frameworks are generally used by many people, so the structure is very good, so the scalability is also very good, and it is constantly upgraded, and you can directly enjoy the benefits of other people's code upgrades.

      The framework is generally the middle layer between the low-level application platform (such as J2EE in java) and high-level business logic.

      ThinkPHP is an open source PHP framework, which was born to simplify enterprise-level application development and agile WEB application development.

      It was originally named FCS. It was officially renamed ThinkPHP on New Year's Day in 2007, and it follows the Apache2 open source Agreement released. The early ideological architecture originated from Struts. Later, after continuous improvement and improvement, it also learned from many excellent foreign frameworks and models, using object-oriented development structure and MVC model, integrating Struts' Action and Dao ideas and JSP's TagLib ( Tag library), RoR's ORM mapping and ActiveRecord mode, which encapsulates CURD and some common operations, single entry mode, etc., has unique performance in template engine, caching mechanism, authentication mechanism and scalability

      Use With ThinkPHP, you can develop and deploy applications more conveniently and quickly. Of course, not just enterprise-level applications, any PHP application development can benefit from the simplicity, compatibility, and speed of ThinkPHP. Simplicity, speed and practicality are the tenets of ThinkPHP's development. To this end, ThinkPHP will continue to absorb and integrate better technologies to ensure its freshness and vitality, and provide the best practices for WEB application development!

      As an overall development solution, ThinkPHP can solve most needs in application development, because it includes the underlying architecture, compatibility processing, base class library, database access layer, template engine, cache mechanism, plug-in mechanism, role authentication, form processing and other commonly used components, and it is more convenient for cross-version, cross-platform and cross-database transplantation. And each component is carefully designed and perfected, and the application development process only needs to focus on your business logic.

      Related recommendations:

      php interview questions three - PHP language basics (basic part) php advanced interview questions php junior interview questions php mysql interview questions

      Common PHP interview questions and answering techniques in 2017

      8 PHP interview questions reflect your understanding of PHP

      The above is the detailed content of PHP advanced interview questions sharing. For more information, please follow other related articles on the PHP Chinese website!

      Related labels:
      source:php.cn
      Statement of this Website
      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
      Popular Tutorials
      More>
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!