Home  >  Article  >  Backend Development  >  Basic PHP interview questions, PHP interview questions_PHP tutorial

Basic PHP interview questions, PHP interview questions_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:44:29866browse

Basic PHP interview questions, PHP interview questions

1. For a website with high traffic, what method do you use to solve the traffic problem?

First, confirm whether the server hardware is sufficient to support the current traffic

Secondly, optimize database access.

Third, external hotlinking is prohibited.

Fourth, control the download of large files.

Fifth, use different hosts to divert the main traffic.

Sixth, use traffic analysis and statistics software.

2. Use PHP to write the code to display the client IP and server IP:

//Display client IP

function get_client_ip() {#

if(getenv('HTTP_CLIENT_IP')) {

$client_ip = getenv('HTTP_CLIENT_IP');

} elseif(getenv('HTTP_X_FORWARDED_FOR')) {

$client_ip = getenv('HTTP_X_FORWARDED_FOR');

} elseif(getenv('REMOTE_ADDR')) {

$client_ip = getenv('REMOTE_ADDR');

} else {

$client_ip = $HTTP_SERVER_VAR['REMOTE_ADDR'];

}

return $client_ip;

}

//Server IP

function get_server_ip(){

if (isset($_SERVER))

{

if($_SERVER['SERVER_ADDR']) $huoqu_ip=$_SERVER['SERVER_ADDR'];

else $huoqu_ip=$_SERVER['LOCAL_ADDR'];

}

else

{

$huoqu_ip=getenv('SERVER_ADDR');

}

return $huoqu_ip;

}

3.MYsql programming interview questions.

(1) In a certain content management system, the message table has the following fields:

id article id

title article title

content article content

category_id article category id

hits clicks

Create the above table and write the MySQL statement:

CREATE TABLE 'message'(

id int(11) NOT NULL auto_increment,

title varchar(200) default NULL,

content blob,

category_id int(11) default NULL,

hits int(11) default NULL,

PRIMARY KEY('id')

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

(2) The same news release system as above: the comment table records the content of user replies, and the fields are as follows:

comment_id reply id

id article id, associated with the id in the message table

comment_content reply content

Now you need to query the database to get a list of article titles in the following format, and sort them by the number of replies, with the highest reply at the top

Article id Article title Number of clicks Number of replies

Use a SQL statement to complete the above query. If the article has no replies, the number of replies will be displayed as 0

SELECT message.id id,message.title title,IF(message.`hits` IS NULL,0,message.`hits`)

hits,IF(comment.`id` is NULL,0,count(*)) number

FROM message LEFT JOIN comment ON message.id=comment.id

GROUP BY message.`id`

(3) In the above content management system, the category table stores classification information, and the fields are as follows (3 points)

category_id int(4) not null auto_increment;

categroy_name varchar(40) not null;

When the user enters an article, select the article category by selecting the drop-down menu

Write how to implement this drop-down menu

function categoryList()

{

$result=mysql_query("select category_id,categroy_name from category")

or die("Invalid query: " . mysql_error());

print("");

}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1048762.htmlTechArticleBasic PHP interview questions, PHP interview questions 1. What method do you use for high-traffic websites? Solve the traffic problem? First, confirm whether the server hardware is sufficient to support the current traffic...
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