Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the interview questions in php

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces which interview questions are in php, which are very detailed and have certain reference value. Friends who are interested must finish reading them.

Which network protocol does 1.nginx use?

Nginx is the application layer. I think from the bottom up, the transport layer uses tcp/ip, and the application layer uses http.

Fastcgi is responsible for scheduling processes.

two。 Did not output the result, what may be the reason, a brief description of the process of solving this problem (hint: there is no problem with grammar)

It is possible that there is no short tag on the server short_open_tag = set to Off,php.ini to enable the short tag control parameter: short_open_tag = On

3. Briefly describe the output of the following program, briefly explain why and how to solve this kind of problem?

Result 1 due to the cast of int and string types, 0 percent = "a"

0 = 0 must be true

PHP is a weak type.

$tmp = 0 = = "a"? 1: 2

Echo $tmp;, so that's 2.

4. A known string is as follows: $str = "1109063 milo 1"

Use one line of code to assign 1109063 of the string to $uid, milo to $user, and 1 to $type

The spaces are as follows

List ($uid, $user, $type) = explode ("", $str)

\ t is as follows

List ($uid, $user, $type) = explode ("\ t", $str)

List ($uid, $user, $type) = sscanf ($str, "d% s% d")

$n = sscanf ($auth, "% d\ t% s% s", $id, $first, $last)

5. List the following types of signed and unsigned range TINYINT SMALLINT MEDIUMINT INT

TINYINT- 2 ^ 7-2 ^ 7-10 ~ 2 ^ 8-1

SMALLINT- 2 ^ 15-2 ^ 15-10 ~ 2 ^ 16-1

MEDIUMINT- 2 ^ 23-2 ^ 23-10 ~ 2 ^ 24-1

INT- 2 ^ 31-2 ^ 31-10 ~ 2 ^ 32-1

6. Assemble the following array into a string i am milo! Day day up!

$str = strtolower (implode ("", $arr))

7. Call the following function to get the function and get the value of count

$count=1

$data = get_list ($cnd,&$count)

Echo $count

8. There are several ways to replace the session mechanism and briefly describe their advantages and disadvantages.

Mysql, memcache, cookie maintain a unique status identification code

9. The possible causes of the following HTTP status codes and how to deal with them

200, 301, 404, 502, 503

two hundred

The request has succeeded, and the desired response header or data body of the request will be returned with this response.

three hundred and one

The requested resource has been permanently moved to a new location, and any future reference to this resource should use one of several URI returned by this response. If possible, the client with the link editing function should automatically change the requested address to the address fed back from the server. Unless otherwise specified, this response is also cacheable. The new persistent URI should be returned in the Location domain of the response. Unless this is an HEAD request, the responding entity should contain a hyperlink to the new URI and a short description. If this is not a GET or HEAD request, the browser forbids automatic redirection unless confirmed by the user, because the conditions of the request may change accordingly. Note: for some browsers that use the HTTP/1.0 protocol, when the POST request they send gets a 301 response, the next redirect request will become GET.

four hundred and four

The request failed and the desired resource was not found on the server. There is no information to tell the user whether the situation is temporary or permanent. If the server knows, the 410 status code should be used to inform the old resource that it is permanently unavailable due to some internal configuration mechanism problem, and there is no address to jump to. The 404 status code is widely used when the server does not want to reveal exactly why the request was rejected or there is no other suitable response available.

five hundred and two

When the server working as a gateway or agent tries to execute the request, it receives an invalid response from the upstream server.

five hundred and three

The server is currently unable to process requests due to temporary server maintenance or overload. This situation is temporary and will recover after a period of time. If the delay time can be predicted, a Retry-After header can be included in the response to indicate the delay time. If this Retry-After information is not given, the client should handle it in the same way as the 500 response. Note: the existence of the 503 status code does not mean that the server must use it when it is overloaded. Some servers simply want to deny connections to clients.

200 OK is fine, and the response documents for GET and POST requests are followed.

The document requested by the 301 Moved Permanently customer is elsewhere, the new URL is given in the Location header, and the browser should automatically access the new URL

404 Not Found could not find the resource at the specified location. This is also a common response.

When the Bad Gateway server acts as a gateway or proxy, it accesses the next server in order to complete the request, but the server returns an illegal reply.

The 503 Service Unavailable server failed to answer due to maintenance or overload. For example, Servlet might return 503 if the database connection pool is full. The server can provide a Retry-After header when it returns 503.

10. There are the following databases that use the native mysql extension to join and query the first ten rows of the user table

Host: 192.168.0.254

Port: 3306

User: one

Pass: piece

Database: db_user

Table: user

$link = mysql_connect ("192.168.0.254 piece 3306", "one", "piece") or die ('Could not connect:'. Mysql_error ())

Mysql_select_db ('db_user',$link)

$query = mysql_query ("select * from user limit 10")

While ($rs = mysql_fetch_array ($query,MYSQL_ASSOC))

{}

11. Use autoload ($class) to realize the automatic loading of classes in the Lib directory and be compatible with subdirectories

$request- > action = lcfirst (implode (array_map)

'ucfirst'

Explode ('-', strtolower ($request- > action))

)))

Function _ _ autoload ($class)

{

$cls = strtolower (str_replace ("_", "/", $class))

If (file_exsits (LIB.$cls.'.php'))

{

Include_once (LIB.$cls.'.php')

}

Else

{

Die ("not found {$class} class")

}

}

Defined ("LIB",'/ data/wwwroot/www.xx.com/lib/')

$author = new Lib_Author ()

Function _ _ authload ($class)

{

$cls = explode ("_", $class)

If (@ is_dir ($cls [1]))

{

If (@ is_file ($cls [2]))

{

Include_once ("CON_PATH". $cls [1].'/. $cls [2]. ".php")

}

Else

{

Dir ('error')

}

}

Else if (@ is_file ($cls [1]. ".php"))

{

Include_once ("CON_PATH". $cls [1]. ".php")

}

Else

{

Dir ('error')

}

}

-

Function _ _ autoload ($class)

{

$cls = explode ("_", $class)

$file = get_file ($cls)

If ($file=='error')

{

Die ('error')

}

Include_once ($file)

}

Function get_file ($dir)

{

If (is_array ($dir))

{

Foreach ($dir as $k = > $v)

{

$tmpdir. = $v.accountables.'

If (is_dir ('CON_PATH'.$tmpdir))

{

Continue ()

}

Else if (is_file ('CON_PATH'.$tmpdir. ".php"))

{

Return 'CON_PATH'.$tmpdir. ".php"

}

Else

{

Return 'error'

}

}

Return 'error'

}

Return 'error'

}

Defined ("CON_PATH", "/ data/wwwroot/www.xx.com/app/cntroller/")

$sb = new controller_sb ()

-

Function _ _ autoload_my_classes ($classname)

{

#... Your logic to include classes here

}

Spl_autoload_register ('_ _ autoload_my_classes')

twelve。 Use set_error_handle to catch errors and output them at your own level

Set_error_handle (callback,level)

Function callback (int $errno, string $errstr [, string $errfile [, int $errline [, array $errcontext]) {

}

Function dealErrorHandler ($errno,$errstr,$errfile,$errline)

{

Switch ($errno) {

Case E_USER_ERROR:

Echo "error [$errno] $errstr fatal error on line $errline in file $errfile"

Break

Case E_USER_WARNING:

Echo "my warning [$errno] $errstr":

Break

Case E_USER_NOTICE:

Echo "my notice [$errno] $errstr"

Break

Default:

Echo "unkonwn error type: [$errno] $errstr"

Break

}

}

Set_erro_handler (dealErrorHandler)

Trigger_error ("notice", E_USER_NOTICE)

Trigger_error ("warning", E_USER_WARNING)

Trigger_error ("error", E_USER_ERROR)

13. Brief introduction of two methods of shielding notice warnings of php programs

Initialize the variable, and the file begins to set the error level or modify the php.ini setting error_reporting

Set_error_handler and @ suppress errors

1. Add: error_reporting (E_ALL & ~ E_NOTICE) to the program

two。 Or modify: error_reporting = E_ALL in php.ini

Change it to: error_reporting = E_ALL & ~ E_NOTICE

3.error_reporting (0); or modify php.inidisplay_errors=Off

14. The role of instanceof, which design patterns are often used

Singleton mode, but other modes will also be used

15. 1023 is expressed in binary, and the calculation process is briefly described.

10-2

1023% 2o1

511% 2 = 1

255% 2 = 1

127% 2 = 1

63% 2 = 1

31% 2 = 1

15% 2 = 1

7% 2 = 1

3% 2 = 1

1% 2 = 1

0 = 0

1023

2 ^ 9 =

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report