PHP FAQ 3

Source: Internet
Author: User
Tags php online

The difference between 1,http and Https

First: HTTP is a Hypertext Transfer Protocol, the information is plaintext transmission, HTTPS is a secure SSL encryption transport protocol

Second: HTTP and HTTPS use a completely different way of connection, the port is not the same, the former 80 or 443 third: HTTP connection is simple, is stateless. The HTTPS protocol is built by the Ssl+http protocol and can be

The network protocol of the identity authentication.

2. How to speed up page loading

1. When the server resource is used, the server resource is shut down immediately when it is opened and not in use.

2, database Add index

3, the page can generate static

4, pictures and other large files placed on a server alone

5, can not query the database as far as possible not to data fetching data, can be placed in the cache.

3. What is the difference between get and post submission methods in a form?

A: Get is a send Request HTTP protocol to receive via URL parameter delivery, while post is entity data that can be submitted with a large amount of information through a form.

4.echo, the difference between Print,print_r:

ECHO is a PHP statement with no return value.

Print,print_r is a function that has a return value.

Print () prints only the value of a simple type variable (such as int,string) Print_r () can print out the value of a complex type variable (such as an array, an object) echo outputs one or more strings

5.session and Cookie Differences

Session is the same as a cookie: cross-page, non-user

The session is not the same as the cookie:

1, session can store any type of data, but the cookie can only store strings

2. Cookies are generated on the server side, stored in the client

Session generated on server side, stored on server side

6. Magic Constants

Answer:

The current line number in the lines file.

the full path and file name of the files file.

Function name

names of class classes

methods Name of method class

7. What are the transactions in the database?

A: a transaction (transaction) is an ordered set of database operations as a unit. If all operations in the group are successful, the transaction is considered successful and the transaction is unsuccessful even if only one operation fails. If all operations are completed, the transaction commits and its modifications are made to all other database processes. If an operation fails, the transaction is rolled back, and the effect of the firm's operations is canceled.

8.1 How to optimize MYSQL database.

1. Select the appropriate data type for the field

1) can use numbers without strings

2) char, varchar, text can be used varchar without char

3) Add not NULL to the field to avoid the presence of the NULL keyword in the table (default value)

2. Select the appropriate field to act as the primary key

1) It is recommended that each table must have a primary key

2) Use a numeric Type field as the primary key

3. Split table

1) Split the field to separate the title of the article from the content

2) split the record to separate this year's record from previous years ' records

4. Add index to the field reasonably

A. Format:

(普通索引)->
创建:CREATE INDEX <索引名> ON tablename (索引字段)

修改:ALTER TABLE tablename ADD INDEX [索引名] (索引字段)

创表指定索引:CREATE TABLE tablename([...],INDEX[索引名](索引字段))

(唯一索引)->

创建:CREATE UNIQUE <索引名> ON tablename (索引字段)

修改:ALTER TABLE tablename ADD UNIQUE [索引名] (索引字段)

创表指定索引:CREATE TABLE tablename([...],UNIQUE[索引名](索引字段))

(主键)->

它是唯一索引,一般在创建表是建立,格式为:

CREATA TABLE tablename ([...],PRIMARY KEY[索引字段])

5. Transaction Processing:

A. Ensure data integrity, such as additions and modifications, both are executed and accesses than either failures fail

mysql_query("BEGIN");


mysql_query("COMMIT");

6, lock the table, optimize transaction processing:

A. We use a SELECT statement to remove the initial data and, with some calculations, update the new value to the table with the UPDATE statement.

The LOCK TABLE statement with the WRITE keyword guarantees that no additional access is allowed to insert, update, or delete the inventory until the UNLOCK TABLES command is executed



mysql_query("UPDATE `orderinfo` SET ordertitle=‘$title‘ where customerid=".$id);
mysql_query("UNLOCK TABLES");

7, using foreign keys, optimize the locking table

A. Map the CustomerID in the CustomerInfo to the CustomerID in OrderInfo,

Any record of no legal CustomerID will not be written in OrderInfo.

CREATE TABLE customerinfo(

customerid INT NOT NULL,

PRIMARY KEY(customerid)

)TYPE = INNODB;

CREATE TABLE orderinfo(

orderid INT NOT NULL,

customerid INT NOT NULL,

PRIMARY KEY(customerid,orderid),

FOREIGN KEY (customerid) REFERENCES customerinfo (customerid) ON DELETE CASCADE

)TYPE = INNODB;

Note: ' On delete CASCADE ', this parameter guarantees that when a record in the CustomerInfo table is deleted, the order is also deleted

All records for that user in the table, note that using foreign keys to define the transaction security type is INNODB;
8. Optimizing Query Statements

A using inner join instead of subquery instead of subquery, using Sphinx instead of like fuzzy query

b It is best to compare operations in the same field, and to minimize the function operation example in establishing a good index field

例子1:

SELECT * FROM order WHERE orderDate<"2008-01-01";(快)
例子 2:

SELECT * FROM order WHERE addtime<24*7;(快)
例子 3:
SELECT * FROM order WHERE title like "%good%";

9, Cache, static

10, choose the appropriate storage engine with Innodb additions and deletions, with MyISAM query

11. Master-Slave Database

12. Load Balancing

13, it is best to take a number type field as a Where condition

14, it is best to take the same type of field to match (to avoid the conversion of data types)

15. Do not add database functions (Index invalidation) on fields that have indexes

PHP Core technologies and best practices

Row Asahi Pine, Chen Wen

When advertising buy8.2 Please briefly describe how the SQL statement is optimized to perform efficiently in the project.

Answer: (1) Select the most efficient table name order

(2) connection order in the WHERE clause

(3) Avoid using ' * ' in the SELECT clause

(4) Replace the HAVING clause with a Where clause

(5) Improve SQL efficiency with intrinsic functions

(6) Avoid using calculations on indexed columns.

(7) Increase the efficiency of the group BY statement by filtering the unwanted records before group by

Off.

9. What are the ways to solve the traffic problem for large-volume websites?

1. Verify that the server's hardware is sufficient to support current traffic

2. Optimize access to the database

3, prohibit external hotlinking

4, control the download of large files

5. Divert primary traffic with different hosts

6, using traffic analysis statistics software

10. A function that can traverse all files and subfolders under a folder (20 points)
function Dir_recurse ( $dir) {

  $i = 1;

  if ($handle = Opendir ($dir)) {

    while ( false!== ($file = Readdir ($handle ) {

      if ($file! = ".") && $file! = "...") {

        if (Is_dir ($dir. "/". $file) = = true) {

          $fullpath = $dir. /. $file;

       dir_recurse ($fullpath);

       echo "$fullpath \ n";

        $i + +;

} else {

      $fullpath = $dir. "/". $file;

     echo "$fullpath \ n",
      $i + +;

  &NBSP;}

 }

}

Closedir ($handle);

}
}
/span>
10.2 Write a function that can traverse all the files and subfolders under a folder.
   function  my_scandir ( $dir) {

    $files = array ();

      if ($handle = Opendir ($dir)) {

        while (($file = Readdir ($handle))!== false) {

          if ($file! = "..." && $file! = ".") {

          if (Is_dir ($dir. "/". $file)) {

            $files [$file] = Scandir ($dir. "/". $file);

         } else {

            $files [] = $file ;

         }

       

   

  &N Bsp;closedir ($handle);

    return $files;

 }

}


Reference: Public number: PHP online

PHP FAQ 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.