1. Describe the main functions of both POSIX-style and compatible Perl-style regular expressions
Ereg Preg_match
Ereg_replace Preg_replace
2. Please describe the effect on PHP system functions after Safe_mode opened in php.ini
Safe_mode is a shared environment that provides a basic security. On a multi-user shared Phpweb server, when this server has the Safe_mode mode enabled, the following functions will be affected. First, the function that attempts to access the file system will be limited, the user ID of the server running, and if you want to attempt to manipulate a file, you must read or write access to the file.
Therefore, the following functions will receive a limit when Safe_mode is turned on:
Ckdir,move_uploaded_file,chgrp,parse_ini_file,chown,rmdir,copy,rename,fopen,require,highlight_file,show_source , Include,symlink,link,touch,mkdir,unlink
All of these are functions related to the operation of the file system, in addition, some PHP extension functions will be limited, can not be directly loaded in the program extension, only to php.ini, and PHP if you need to execute the operating system program, must be in safe_mode_exec_ DIR Specifies the path to the program, otherwise execution will fail. There are also exec,shell_exec,pasathru,system,popen and other functions that will receive restrictions
3. What are some of the magic method functions in PHP5, please illustrate their usage
__sleep
__wakeup
__tostring
__set_state
__construct,
__destruct
__call,
__get,
__set,
__isset,
__unset
__sleep,
__wakeup,
__tostring,
__set_state,
__clone
__autoload
4. Please write the assignment and explain how to run the PHP script at the command line (write out two ways) and pass the parameters to the PHP script at the same time?
$PHP _home/bin/php-r ' echo $argv [1]; ' Hello
$PHP _home/bin/php hello.php Hello
window, assuming that the PHP installation directory is C:\Program Files\php5\, then use the Command window to enter the path, typing PHP hello.php carriage return, the current path will be executed under the hello.php file,
If you want to point to the other path PHP file, can be in the PHP path/hello.php, this form is called the CLI mode, we usually see through the browser of the kind of the CGI mode, as for the transfer parameters, PHP file in the CLI mode, directly by the name of the file after the parameter, A number of parameters in the middle with a space, in the PHP file is passed two variables to get parameters, one is $argv, one is $ARGC, the former is an array of parameters passed, the default first is the name of the PHP file, the latter is the number of $argv array.
Under Linux, the General program installation will be installed under the/usr/bin/php, can be viewed through the man PHP, if there is information to use, similar to the use of window. If this step is set up, then you can directly php php files to run PHP files, if man php no information, then the current PHP executable file is not in the environment path, you can modify the environment path contains PHP path, can also be similar to the window into the PHP path, in the execution of PHP PHP files. Other similar to window under.
5. What is the garbage collection mechanism of PHP?
In PHP, when there are no variables pointing to this object, the object becomes garbage. PHP will destroy it in memory, which is the GC garbage disposal mechanism of PHP to prevent memory overflow.
When a PHP thread ends, all memory space currently occupied is destroyed, and all objects in the current program are destroyed at the same time. GC processes are typically run with each session. The GC is designed to automatically destroy deleted files after the session file expires.
Performing these functions can also play a role in recycling
__destruct/unset/mysql_close
6. Enables an object to have a foreach loop like an array, requiring that the property be private.
(Iterator mode PHP5 implementation, write a class of implementation iterator interface)
PHP5 began to support the interface, and built-in iterator interface, so if you define a class, and implement the iterator interface, then your class object is Zend_iter_object, otherwise it is zend_iter_plain_object.
For Zend_iter_plain_object classes, foreach obtains an array of default properties for the object through Hash_of, and then foreach the array.
For Zend_iter_object class objects, foreach is done by invoking the iterator interface-related functions implemented by the object, so for this question, the following answers can be made:
[PHP]
Class Sample Implements Iterator
{
Private $_items = Array (1,2,3,4,5,6,7);
Public Function __construct () {
;//void
}
Public Function Rewind () {Reset ($this->_items);}
Public function current () {return current ($this->_items);}
Public Function key () {return key ($this->_items);}
Public function Next () {return next ($this->_items);}
Public Function valid () {return ($this->current ()!== false);}
}
$sa = new sample ();
foreach ($sa as $key = = $val) {
Print $key. "=". $val;
}[/php]
The above code runs normally under my PHP 5.3.
7. Please write a PHP code to ensure that multiple processes write to the same file successfully
function WriteData ($path, $mode, $data) {
$fp = fopen ($path, $mode);
$retries = 0;
$max _retries = 100;
do {
if ($retries > 0) {
Usleep (rand (1, 10000));
}
$retries + = 1;
}while (!flock ($FP, LOCK_EX) and $retries <= $max _retries);
if ($retries = = $max _retries) {
return false;
}
Fwrite ($fp, "$data \ n");
Flock ($FP, lock_un);
Fclose ($FP);
return true;
}
8. Implementing a two-way queue with PHP
9. Use a regular expression to extract the specified attribute value for a specified label in an identity language (HTML or XML) snippet (consider the case where the property value pair is irregular, such as casing insensitivity, a space between the attribute name value and the equals sign, and so on). This assumes that you need to extract the value of the Attr property of the test tag, build your own string containing the label
10. Use the socket correlation function (non-curl) to construct a POST request that is sent to a specified request path (such as Http://www.example.com:8080/test) to the specified port of the specified HTTP server. The following variables are included in the request:
User name (username): a gentle knife
Password (PWD):&123=321&321=123&
Personal Profile (Intro): Hello world!
And the HTTP server requires the following cookies for simple user action tracking:
Cur_query:you&me
LAST_TM: ... (Last requested Unix timestamp, 10 minutes before the current request time)
CUR_TM: ... (The Unix timestamp of the current request)
The setting time-out is 10 seconds, and after the request is made, the response content of the HTTP server is output.
function encode ($data, $sep = ' & ') {
while (list ($k, $v) = each ($data)) {
$encoded. = ($encoded? "$sep": "");
$encoded. = Rawurlencode ($k). " = ". Rawurlencode ($v);
}
Return $encoded;
}
Function post ($url, $post, $cookie) {
$url = Parse_url ($url);
$post = Encode ($data, ' & ');
$cookie = Encode ($cookieArray, '; ');
$fp = Fsockopen ($url [' Host '], $url [' Port ']? $url [' Port ']: $errno, $ERRSTR, 10);
if (! $fp) return "Failed to open socket to $url [host]";
Fputs ($FP, sprintf ("POST%s%s%s http/1.0\n", $url [' Path '], $url [' query ']? "?": "", $url [' query ']);
Fputs ($FP, "Host: $url [host]\n");
Fputs ($fp, "content-type:application/x-www-form-urlencoded\n");
Fputs ($FP, "Content-length:".) Strlen ($encoded). "\ n");
Fputs ($FP, "Cookie: $cookie \ n \ nthe");
Fputs ($fp, "connection:close\n\n");
Fputs ($fp, "$post \ n");
while (!feof ($fp)) {
Echo fgets ($FP, 128);
}
Fclose ($FP);
}
$url = ' http://www.example.com:8080/test ';
$encoded = username= Gentle Knife & pwd=
$post = Array (
' Username ' = ' a gentle knife ',
' pwd = &123=321&321=123& ',
' intro = ' Hello world! '
);
$cookie = Array (
' Cur_query ' = ' you&me,
' Last_tm ' = Time ()-600,
' Cur_tm ' = Time ()
);
Post ($url, $post, $cookie);
11. How do you check the efficiency of the PHP script execution (usually the script execution time) and the efficiency of the database SQL (usually the database query time) and locate and analyze the bottleneck of script execution and database query?
1. Script execution time, enabling Xdebug, using wincachegrind analysis.
2. database query, MySQL uses explain analysis query, enable slow query log record slow queries.
3, Xdebug statistics function execution times and specific time analysis.
4, the online system uses Strace to track the specific system calls of the related process.
PHP LAMP Engineer Test Paper
Question 1
What is does print out?
A) 3
B) False
C) Null
D) 1
E) 0
Question 2
Which of the following snippets prints a representation of a, with a decimal places?
A) printf ("%.2d\n", 42);
B) printf ("%1.2f\n", 42);
C) printf ("%1.2u\n", 42);
Question 3
Given
$text = ' content-type:text/xml ';
Which of the following prints ' Text/xml '?
A) Print substr ($text, STRCHR ($text, ': '));
B) Print substr ($text, STRCHR ($text, ': ') + 1);
C) Print substr ($text, Strpos ($text, ': ') + 1);
D) Print substr ($text, Strpos ($text, ': ') + 2);
E) Print substr ($text, 0, STRCHR ($text, ': ')
Question 4
What is the $a of the value?
$a = In_array (' n ', Array (' 1 ')) = = Var_dump (' 01 ' = = 1);
?>
A) True
B) False
Question 5
What is the value of $result in the following PHP code?
function Timestwo ($int) {
$int = $int * 2;
}
$int = 2;
$result = Timestwo ($int);
?>;
Answer:null
Question 6
The code below ___________ because ____________.
Class Foo {
?>
function Bar () {
print "Bar";
}
}
?>
A) would work, class definitions can is split up into multiple PHP blocks.
B) won't work, class definitions must is in a single PHP block.
C) won't work, class definitions must is in a single file but can is in multiple PHP blocks.
D) would work, class definitions can is split up into multiple files and multiple PHP blocks.
Question 7
When turned on, ____________ would _________ your script with different variables from HTML forms and cookies.
A) Show_errors, enable
B) Show_errors, show
C) Register_globals, enhance
D) Register_globals, inject
Question 8
What would be is the output of the following PHP code:
echo Count (strlen ("http://php.net"));
?>
Answer:1
Question 9
What's the best all-purpose, comparing, strings?
A) Using the Strpos function
B) Using the = = operator
C) Using strcasecmp ()
D) Using strcmp ()
Question 10
What is the difference between "print ()" and "Echo ()"?
Answer:print is a function,echo is a language construct