It’s been more than a month since I arrived in Beijing on August 15th until today. During this period of time, I have been preparing for written examinations and interviews. I have interviewed with more than 10 companies, large and small, and have only recently settled down. I felt like I had grown a lot during the interview. When I first arrived in this strange city, I was at a loss. I didn’t know how to take the subway, squeeze into buses, or live a proper life. . .
The interview is the first hurdle to enter the workplace. Because my own school was too ordinary, I encountered various discomforts during the interview. Compared with those with higher education, my confidence was really low. The direction of my interview is as a PHP development engineer, mainly working on website backend, APP interface, etc. The companies I interviewed, test questions, and experiences are all on my personal website. If you are interested, you can take a look: http://dwz.cn/1KMpea. The following are the common knowledge points that I have summarized during this period of time in interviews. I hope it will be helpful to everyone. Please feel free to point out any mistakes.
Summary:
I summarized the php part according to the frequently asked questions in interviews. The following questions have a high rate of appearance in interviews. The question is relatively basic
-----------------------------PHP part------------------ ------
The difference between several output functions echo, print(), print_r(), sprintf(), var_dump() in PHP
1: echo: Yes The statement is not a function, has no return value, can output multiple variable values, and does not require parentheses. Arrays and objects cannot be output, only simple types (such as int, string) can be printed.
2: print: It is a statement, not a function. It has a return value of 1 and can only output one variable. No parentheses are needed. Arrays and objects cannot be output, only simple types (such as int, string) can be printed.
3 ) to make print_r not output but return the processed value of print_r4: printf: It is a function, which formats the text and then outputs it (see C language)
5: sprintf: It is a function, similar to printf, But it does not print, but returns the formatted text (this function writes the formatted string into a variable instead of outputting it), and the rest is the same as printf.
For example: $str = "Hello"; $number = 123;
$txt = sprintf("%s world. Day number %u",$str,$number); //Output: Hello world. Day number 123
6: var_dump(): function, outputs the content, type of the variable or the content, type, and length of the string. Often used for debugging.
Write a function to solve the problem of multiple threads reading and writing a file at the same time.
<span> 1</span> <?<span>php </span><span> 2</span><span>$fp</span> = <span>fopen</span>("/tmp/lock.txt","w+"<span>); </span><span> 3</span><span>if</span>(<span>flock</span>(<span>$fp</span>, LOCK_EX)){<span>//</span><span> 进行排它型锁定</span><span> 4</span><span>fwrite</span>(<span>$fp</span>,"Write something here\n"<span>); </span><span> 5</span><span>flock</span>(<span>$fp</span>, LOCK_UN);<span>//</span><span> 释放锁定</span><span> 6</span> }<span>else</span><span>{ </span><span> 7</span><span>echo</span> "Couldn't lock the file !"<span>; </span><span> 8</span><span> } </span><span> 9</span><span>fclose</span>(<span>$fp</span><span>); </span><span>10</span> ?>
Usage plan for
Sessionthat disables cookies,
setSessionexpiration method, corresponding function:
pass the value through url,Session
id Attached to the url (disadvantage: there cannot be purely static pages in the entire site, because the purely static page
Session
id will not be passed to the next page)
By hiding the form, put the Session id in the form The hidden text box is submitted together with the form (disadvantage: it does not apply to non-form situations where the tag directly jumps)
Configure the php.ini file directly and change the Session in the php.ini file .use_trans_sid= 0 is set to 1, (it seems not supported on win)
Save the Session ID in the form of files, databases, etc., and call it manually during the cross-page process
<span> 1</span> 第一种 <span>setcookie</span><span>() 直接用setcookie设置<strong>Session</strong> id的生命周期。
</span><span> 2</span><span> 3</span><span>$lifetime</span>=60; <span>//</span><span>保存1分钟 </span><span> 4</span><span><strong>Session</strong>_start</span><span>();
</span><span> 5</span><span>setcookie</span>(<span><strong>Session</strong>_name</span>(), <span><strong>Session</strong>_id</span>(), <span>time</span>()+<span>$lifetime</span>, "/"<span>);
</span><span> 6</span> 第二种 <span><strong>Session</strong>_set_cookie_params</span><span>()
</span><span> 7</span><span>$lifetime</span>=60;<span>//</span><span>保存1分钟</span><span> 8</span><span><strong>Session</strong>_set_cookie_params</span>(<span>$lifetime</span><span>);
</span><span> 9</span><span><strong>Session</strong>_start</span><span>();
</span><span>10</span><span><strong>Session</strong>_regenerate_id</span>(<span>true</span><span>);
</span><span>11</span> 其中<strong>Session</strong>_regenerate_id();方法用于改变当前<strong>Session</strong>_id的值,并保留<strong>Session</strong>中数组的值。参数默认为 <span>false</span>,如果设置为true则改变<strong>Session</strong>_id的值,并清空当前<strong>Session</strong>数组。
What are the characteristics of json format data
JSON is a lightweight data exchange format. It is based on a subset of ECMAScript. JSON uses a completely language-independent text format, but also uses conventions similar to the C language family (including C, C++, C#, Java, JavaScript, Perl, Python, etc.). These properties make JSON an ideal data exchange language. Easy for humans to read and write, and easy for machines to parse and generate (network transmission rate).
The structure of JSON is based on the following two points1. A collection of "name/value" pairs
In different languages, it is understood as object
(object), record (record), structure (struct ), dictionary, hash table, keyed list, etc. 2. An ordered list of values In most languages, it is understood as an array1: file_get_contents gets the contents of the file (can be obtained by get and post), and the entire file is read into a string
2: Use fopen to open the url, and get the content by get (with the help of fgets( ) function)
3: Use the fsockopen function to open the url (can be obtained by get and post), and obtain the complete data by get, including header and body4: Use the curl library to obtain the content , before using the curl library, you need to check php.ini to see if the curl extension has been turned on
What are the common PHP array functions? (The role of array_merge, in_array)
1. Array Basic functions of operations
array_values($arr); //Get the value of the array
array_keys($arr); //Get the key name of the array
array_flip($arr ; Is a strict type check
array_reverse($arr); key_exists(" apple", $arr); //Retrieve whether the given key name exists in the array
array_count_values($arr); 2. Array segmentation and filling
array_slice($arr, 0, 3); //You can take out a segment of the array, this function ignores the key name (array segmentation)
array_splice($ arr, 0, 3, array("black","maroon")); //You can take out a section of the array. The difference from the previous function is that the returned sequence is deleted from the original array
array_chunk( $arr, 3, TRUE); //An array can be split into multiple arrays. TRUE retains the key name of the original array (split multiple arrays)
4. Array and stack, queue
array_push($arr, "apple", "pear"); //Push one or more elements into the end of the array stack (push), and return the number of elements pushed into the stack Number
array_pop($arr); // Pop the last element of the array stack
array_shift($arr); // Move the first element out of the array and return it (array The length is reduced by 1, other elements are moved forward one position, the numeric key name is changed to count from zero, and the text key name remains unchanged)
array_unshift($arr,"a",array(1,2)); // Insert one or more elements at the beginning of the array
6. Sorting of the array
sort($arr); //From small to large, ignoring key names rsort($arr); //By From large to small, ignore the key name
asort($arr); //From small to large, keep the key name arsort($arr); // From big to small, keep the key name
ksort($arr); // Sort by key name in positive order
7. Array calculation
array_sum($arr); //Perform summation operation on all elements inside the array (sum of array elements)
array_merge($arr1, $arr2); / / Merge two or more (same string key name, the latter overwrites the previous, the same numeric key name, the latter is appended to the end)
array_diff($arr1, $arr2); / /Return the difference set result array array_diff_assoc($arr1, $arr2, $arr3); //Return the difference set result array, the key names are also compared
array_intersect($arr1, $arr2); // Return the intersection result array array_intersect_assoc($arr1, $arr2); //Return the intersection result array, the key names are also compared
8. Other array functions
array_unique($arr); //Remove For repeated values in the array, the original key names will be retained in the new array
shuffle($arr);
方法:__construct(),__destruct(), 方法重载:__call(),__callStatic()。属性重载:__get(),__set(),__isset(),__unset(),这四个只对类中,私有,受保护的成员属性有效
__toString(),__autoload();
_set_state(); //自 PHP 5.1.0 起当调用 var_export() 导出类时,此静态 方法会被调用。 本方法的唯一参数是一个数组。
__clone(); //通常用于对副本进行重新初始化,
说明:this指副本对象引用,that指原对象引用 等方法在 PHP 中被称为”魔术方法”。PHP 将所有以 __(两个下划线)开头的类方法保留为魔术方法。所以在定义类方法时,除了上述魔术方法,建议不要以 __ 为前缀。在命名自己的类方法时不能使用这些方法名,除非是想使用其魔术功能。
常量:__LINK__ //文件中的当前行号。
__FILE__ //文件的完整路径和文件名。如果用在被包含文件中,则返回被包含的文件名。
__DIR__ //文件所在的目录。如果用在被包括文件中,则返回被包括的文件所在的目录,它等价于 dirname(__FILE__)。
__FUNCTION__ //函数名称。自 PHP 5 起本常量返回该函数被定义时的名字(区分大小写)。在 PHP 4 中该值总是小写字母的。
__CLASS__ //类的名称。自 PHP 5 起本常量返回该类被定义时的名字(区分大小写)。在 PHP 4 中该值总是小写字母的。
__METHOD__ //类的方法名(PHP 5.0.0 新加)。返回该方法被定义时的名字(区分大小写)。
__NAMESPACE__ //当前命名空间的名称(大小写敏感)。这个常量是在编译时定义的(PHP 5.3.0 新增)
PHP 如何获取客户端的IP地址,
用$_SERVER获取的IP地址有什么问题?
$_SERVER['REMOTE_ADDR'] ; 通过全局数组来获得
getenv('REMOTE_ADDR') ; 通过环境变量来获得
当客户机使用代理的时候获取不到真实的IP地址
写一个函数,可以遍历文件夹下的所有文件和文件夹。
<span> 1</span><span>function</span> get_dir_info(<span>$path</span><span>){ </span><span> 2</span><span>$handle</span> = <span>opendir</span>(<span>$path</span>);<span>//</span><span>打开目录返回句柄</span><span> 3</span><span>while</span>((<span>$content</span> = <span>readdir</span>(<span>$handle</span>))!== <span>false</span><span>){ </span><span> 4</span><span>$new_dir</span> = <span>$path</span> . DIRECTORY_SEPARATOR . <span>$content</span><span>; </span><span> 5</span><span>if</span>(<span>$content</span> == '..' || <span>$content</span> == '.'<span>){ </span><span> 6</span><span>continue</span><span>; </span><span> 7</span><span> } </span><span> 8</span><span>if</span>(<span>is_dir</span>(<span>$new_dir</span><span>)){ </span><span> 9</span><span>echo</span> "<br>目录:".<span>$new_dir</span> . '<br>'<span>; </span><span>10</span> get_dir_info(<span>$new_dir</span><span>); </span><span>11</span> }<span>else</span><span>{ </span><span>12</span><span>echo</span> "文件:".<span>$path</span>.':'.<span>$content</span> .'<br>'<span>; </span><span>13</span><span> } </span><span>14</span><span> } </span><span>15</span><span> } </span><span>16</span> get_dir_info(<span>$dir</span>);
有mail.log的一个文档,内容为若干邮件地址,用’\n’分隔换行。挑选sina.com的地址(包括从文件读取、过滤到列印出来)。
思路1:用正则表达式(比较慢,效率地,不推荐用)
思路2:cat mail.log | grep sina.com
PHP缓存技术有哪些? tp是局部还是完全缓存?
1. 全页面静态化缓存,也就是将页面全部生成html静态页面,用户访问时直接访问的静态页面,而不会去走php服务器解析的流程
2. 页面部分缓存,将一个页面中不经常变的部分进行静态缓存,而经常变化的块不缓存,最后组装在一起显示
3. 数据缓存,通过一个id进行请求的数据,将数据缓存到一个php文件中,id和文件是对应的,下次通过这个id进行请求时 直接读php文件
4. 查询缓存,和数据缓存差不多,根据查询语句进行缓存;
5. 常用的缓存技术有:redis和memcache
个人认为tp应该是全局缓存 因为:tp缓存实在本地生成一个php文件来存储数据库中读取出来的数据
strlen()与mb_strlen的作用与区别
在PHP中,strlen与mb_strlen是求字符串长度的函数PHP内置的字符串长度函数strlen无法正确处理中文字符串,它得到的只是字符串所占的字节数。对于GB2312的中文编码,strlen得到的值是汉字个数的2倍,而对于UTF-8编码的中文,就是3倍(在 UTF-8编码下,一个汉字占3个字节)。
采用mb_strlen函数可以较好地解决这个问题。mb_strlen的用法和strlen类似,只不过它有第二个可选参数用于指定字符编码。例如得到UTF-8的字符串$str长度,可以用 mb_strlen($str,'UTF-8')。如果省略第二个参数,则会使用PHP的内部编码。内部编码可以通过 mb_internal_encoding()函数得到。
需要注意的是,mb_strlen并不是PHP核心函数,使用前需要确保在php.ini中加载了php_mbstring.dll,即确保“extension=php_mbstring.dll”这一行存在并且没有被注释掉,否则会出现未定义函 数的问题。
写一个函数,尽可能高效的从一个标准url中取出扩展名
$arr = parse_url('http://www.sina.com.cn/abc/de/fg.php?id=1');$result = pathinfo($arr['path']);var_dump($arr);
var_dump($result['extension']);
php.ini 中safe mod关闭 影响哪些函数和参数,至少写6个?
move_uploaded_file() exec()
system() passthru()
popen() fopen()
mkdir() rmdir()
rename() unlink()
copy() chgrp()
chown() chmod()
touch() symlink()
link() parse_ini_file()
set_time_limit() max_execution_time mail()
一群猴子排成一圈,按1,2,…,n依次编号。然后从第1只开始数,数到第m只,把它踢出圈,从它后面再开始数,再数到第m只,在把它踢出去…,如此不停 的进行下去,直到最后只剩下一只猴子为止,那只猴子就叫做大王。要求编程模拟此过程,输入m、n, 输出最后那个大王的编号。
<span> 1</span> <<span>?php </span><span> 2</span><span>function</span> fuhuan(<span>$allnum</span>, <span>$ti</span><span>){ </span><span> 3</span><span>$arr</span> = <span>array</span><span>(); </span><span> 4</span><span>for</span>(<span>$i</span> = 0; <span>$i</span> < <span>$allnum</span>; <span>$i</span>++<span>){ </span><span> 5</span><span>$arr</span>[<span>$i</span>] = <span>$i</span><span>; </span><span> 6</span><span> } </span><span> 7</span><span> 8</span><span>$nums</span> = 1<span>; </span><span> 9</span><span>while</span>(<span>count</span>(<span>$arr</span>) > 1<span>){ </span><span>10</span><span>foreach</span> (<span>$arr</span><span>as</span><span>$key</span> => <span>$value</span><span>) { </span><span>11</span><span>if</span>(<span>$nums</span> == <span>$ti</span><span>){ </span><span>12</span><span>unset</span>(<span>$arr</span>[<span>$key</span><span>]); </span><span>13</span><span>$nums</span> = 1<span>; </span><span>14</span> }<span>else</span><span>{ </span><span>15</span><span>$nums</span>++<span>; </span><span>16</span><span> } </span><span>17</span><span> } </span><span>18</span><span> } </span><span>19</span><span>$new_arr</span> = <span>array_values</span>(<span>$arr</span><span>); </span><span>20</span><span>var_dump</span>(<span>$new_arr</span>[0] + 1<span>); </span><span>21</span><span> } </span><span>22</span> fuhuan(10,10);
isset() 、empty()与is_null的区别
1、当变量未定义时,is_null()和“参数本身”是不允许作为参数判断的,会报Notice警告错误;
2、empty,isset首先都会检查变量是否存在,然后对变量值进行检测。而is_null 和 “参数本身”只是直接检查变量值,是否为null,因此如果变量未定义就会出现错误!
3、isset():仅当null和未定义,返回false;
4、empty():""、0、"0"、NULL、FALSE、array(),未定义,均返回false;
5、is_null():仅判断是否为null,未定义 报警告;
6、变量本身作为参数,与empty()一致,但接受未定义变量时,报警告;
求两个文件的相对路径
<span> 1</span> getpath('/a/b/c/d/e.php', '/a/d/12/34/c.php'<span>); </span><span> 2</span><span> 3</span><span>function</span> getpath(<span>$a</span>, <span>$b</span><span>){ </span><span> 4</span><span>$aarr</span> = <span>explode</span>('/', <span>$a</span><span>); </span><span> 5</span><span>$barr</span> = <span>explode</span>('/', <span>$b</span><span>); </span><span> 6</span><span>$count</span> = <span>count</span>(<span>$barr</span>) - 2<span>; </span><span> 7</span><span>$pathinfo</span> = ''<span>; </span><span> 8</span><span>for</span>(<span>$i</span> = 1; <span>$i</span> <= <span>$count</span>; <span>$i</span>++<span>){ </span><span> 9</span><span>if</span>(<span>$aarr</span>[<span>$i</span>] == <span>$barr</span>[<span>$i</span><span>]){ </span><span>10</span><span>$pathinfo</span> .= '../'<span>; </span><span>11</span> }<span>else</span><span>{ </span><span>12</span><span>$pathinfo</span> .= <span>$barr</span>[<span>$i</span>] . '/'<span>; </span><span>13</span><span> } </span><span>14</span><span> } </span><span>15</span><span>echo</span><span>$pathinfo</span><span>; </span><span>16</span> }
MVC的优缺点
1. Advantages of MVC
(1) You can create and use multiple views for a model at runtime at the same time. The change-propagation mechanism ensures that all related views receive model data changes in a timely manner, so that all associated views and controllers can behave in sync.
(2) 与 与
, allows the replacement view and controller object , and can be dynamically opened or closed according to needs, and even during the operation period,
objects
replace. (3)Model portability. Because the model is independent of the view, a model can be ported independently to work on a new platform. All that is needed is new modifications to views and controllers on the new platform. (4) Potential frame structure. Application frameworks can be built based on this model, not just for designing interfaces.
2. Disadvantages of MVC
(1) Increases the complexity of system structure and implementation. For simple interfaces, strictly following MVC and separating the model, view and controller will increase the complexity of the structure, may generate too many update operations, and reduce operating efficiency.
Too tight a connection between the view and the controller. The view and the controller are components that are separated from each other, but are indeed closely related. The view does not have the existence of the controller, and its application is very limited, and vice versa, which hinders their independent reuse. (3) Inefficient access to model data by views. Depending on the model operation interface, the view may need to be called multiple times to obtain enough display data. Unnecessarily frequent access to unchanged data will also harm operational performance. (4) Currently, generally advanced interface tools or constructors do not support the MVC mode. Adapting these tools to fit MVC needs and creating separate components is expensive, making it difficult to use MVC.
SessionThe connection and difference (operating mechanism) with cookies,
SessionShared problem solutions: Differences and connections : Use Session_start() to call Session. The server generates the Session file while generating the Session ID hash value and the Session name with the default value of PHPSESSID, and sends it to the client The sending variable is PHPSESSID(Session name) (default) value is a 128-bit hash value. The server will interact with the client through this cookie. The value of the Session variable is serialized internally by PHP and stored in a text file on the server machine. It interacts with the client's coolie whose variable name is PHPSESSID by default. That is, the server automatically sends the http header: header('Set-Cookie: Session_name()=Session_id(); path=/'); that is, setcookie(Session
_name(),Session_id( )); When jumping to a new page from this page and calling Session
_start(), PHP will check theSession data stored on the server side associated with the given ID, and if it is not found, create a new data set. Sharing plan: 1: Use Session/' target='_blank'>database to save
Session, use the database to save
Session, even if the server is down, it will be fine, Session
is still there.Problem: The program needs to be customized; reading and writing the database for each request is expensive. In addition, the database is a single point. You can do a hash of the database to solve this problem.
2: Use Memcached to save Session
. This method is similar to the database, and the memory access performance is much better than the database. 🎜🎜🎜Problem: The program needs to be customized, which increases the workload; the data stored in 🎜Memcached🎜 needs to be serialized, which is inefficient and data is easily lost when the computer is powered off or restarted; 🎜🎜🎜3: 通过加密的cookie,在A服务器上登录,在用户的浏览器上添加加密的cookie,当用户访问B服务器时,检查有无Session,如果没有,就检验 Cookie是否有效,Cookie有效的话就在B服务器上重建Session。简单,高效, 服务器的压力减小了,因为Session数据不存在服务器磁盘上。根本就不会出现Session读取不到的问题。
问题:网络请求占用很多。每次请求时,客户端都要通过cookie发送Session数据给服务器,Session中数据不能太多,浏览器对cookie 的大
小存在限制。不适合高访问量的情况,因为高访问量的情况下。
正则表达式
匹配中文字符的正则表达式: [\u4e00-\u9fa5] --------------------linux部分--------------------- core文件是什么,有什么用? 不用core文件,程序出了问题产生信号是否知道?答:内核向进程发信号嘛。 共享内存除了文件映射还有什么方式? 共享内存对象映射。 二者有什么区别: 答:内存映射文件是由一个文件到一块内存的映射,使应用程序可以通过内存指针对磁盘上的文件进行访问,其过程就如同对加载了文件的内存的访问,因此内存文件映射非常适合于用来管理大文件。 top:命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器。 ps:查看进程 mv:移动或者更改文件 find:在子目录中搜索匹配的文件 df:linux中df命令参数功能:检查文件系统的磁盘空间占用情况。 cat:把一个或多个文件内容显示到标准输出 chmod:改变文件属性 chgrp:改变用户分组 grep:在文件内进行搜索 wc:命令的功能为统计指定文件中的字节数、字数、行数, 并将统计结果显示输出。 Linux文件属性有哪些?(共十位) -rw-r--r--那个是权限符号,总共是- --- --- ---这几个位。 第一个短横处是文件类型识别符:-表示普通文件;c表示字符设备(character);b表示块设备(block);d表示目录 (directory);l表示链接文件(link);后面第一个三个连续的短横是用户权限位(User),第二个三个连续短横是组权限位 (Group),第三个三个连续短横是其他权限位(Other)。每个权限位有三个权限,r(读权限),w(写权限),x(执行权限)。如果每个权限位都 有权限存在,那么满权限的情况就是:-rwxrwxrwx;权限为空的情况就是- --- --- ---。 权限的设定可以用chmod命令,其格式位:chmod ugoa+/-/=rwx filename/directory。例如: 一个文件aaa具有完全空的权限- --- --- ---。 chmod u+rw aaa(给用户权限位设置读写权限,其权限表示为:- rw- --- ---) chmod g+r aaa (Set the permission to the group as readable, and its permission is expressed as: - --- r-- ---) chmod ugo+rw aaa (Give the user, group , other users or groups set permissions to read and write, the permissions are expressed as: - rw- rw- rw-) If aaa has full permissions - rwx rwx rwx. chmod u-x aaa (remove user executable permissions, permissions are expressed as: - rw- rwx rwx) If you want to give aaa customized permissions - rwx r-x r-x, the command is: chmod u=rwx, go=rx aaa Apache with Nginx nginx is good at processing static files. Nginx’s static processing performance is more than 3 times higher than Apache 3: Reason: This is due to Nginx using the latest epoll (Linux 2.6 kernel) and kqueue (freebsd) network I/O model, while Apache uses the traditional select model. Currently, Squid and Memcached, which can withstand high concurrent access under Linux, all use the epoll network I/O model. To handle the reading and writing of a large number of connections, the select network I/O model adopted by Apache is very inefficient. The difference between cgi and fastcgi cgi was used more in 2000 or earlier. In the past, web servers generally only processed static requests. The web server would then process the request based on the content of the request. Fork a new process to run an external C program (or perl script...). This process will return the processed data to the web server. Finally, the web server will send the content to the user, and the process just forked will also exit. If the user requests to change the dynamic script next time, the web server will fork a new process again, and the cycle will continue. Later, a more advanced way appeared, the web server can have a built-in perl interpreter or php interpreter. In other words, these interpreters are made into modules, and the web server will start these interpreters when it starts. When new dynamic requests come in, the web server parses these perl or php scripts by itself, eliminating the need to re-fork a process and improving efficiency. fastcgi’s method is that when the web server receives a request, it will not re-fork a process (because this process is started when the web server starts and will not exit). The web server directly passes the content to This process (inter-process communication, but fastcgi uses another method, tcp communication), this process processes the request after receiving it, returns the result to the web server, and finally waits for the next request to arrive, instead of quit. The difference between gFastcgi and CGI is: The difference between select, poll and epoll select select first appeared in 4.2BSD in 1983. It monitors an array of multiple file descriptors through a select() system call , when select() returns, the ready file descriptors in the array will be modified by the kernel, so that the process can obtain these file descriptors for subsequent read and write operations. select is currently supported on almost all platforms, and its good cross-platform support is also one of its advantages. In fact, from now on, this is one of its few remaining advantages. One disadvantage of select is that there is a maximum limit on the number of file descriptors that a single process can monitor, which is generally 1024 on Linux. However, this limit can be increased by modifying the macro definition or even recompiling the kernel. In addition, the data structure maintained by select() stores a large number of file descriptors. As the number of file descriptors increases, its copy overhead also increases linearly. At the same time, due to the delay in network response time, a large number of TCP connections are inactive, but calling select() will perform a linear scan of all sockets, so this also wastes a certain amount of overhead. poll poll was born in System V Release 3 in 1986. It is not much different from select in nature, but poll does not have a maximum file descriptor limit. poll and select also have a shortcoming that the array containing a large number of file descriptors is copied as a whole between the user mode and the kernel's address space, regardless of whether these file descriptorsare ready or not, its The overhead increases linearly with the number of file descriptors. In addition, after select() and poll() tell the process about the ready file descriptor, if the process does not perform IO operations on it, then the next time select() and poll() are called, it will happen again Reporting these file descriptors so they generally don't lose ready messages is called Level Triggered. epoll It wasn’t until Linux2.6 that an implementation method directly supported by the kernel appeared, that is epoll, which has almost all the advantages mentioned before and is recognized as the best performance under Linux2.6 Multi-channel I/O ready notification method. epoll can support both level triggering and edge triggering (Edge Triggered), which only tells the process which file descriptor has just become ready, it only says it once, if we do not take action, then it will not tell it again , this method is called edge triggering). In theory, the performance of edge triggering is higher, but the code implementation is quite complicated. epoll also only notifies those ready file descriptors, and when we call epoll_wait() to obtain a ready file descriptor, what is returned is not the actual descriptor, but a number representing the number of ready descriptors value, you only need to get the corresponding number of file descriptors from an array specified by epoll. Memory mapping (mmap) technology is also used here, which completely eliminates the need for these file descriptors in the system. The overhead of copying when called. Another essential improvement is that epoll adopts an event-based readiness notification method. In select/poll, the kernel scans all monitored file descriptors only after the process calls a certain method, while epoll registers a file descriptor through epoll_ctl() in advance. Once based on a certain file description When the descriptor is ready, the kernel will use a callback mechanism similar to callback to quickly activate this file descriptor , and will be notified when the process calls epoll_wait(). Difference between Memcache and Redis
The above has introduced the PHP interview summary, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.
匹配双字节字符(包括汉字在内):[^\x00-\xff]
匹配空行的正则表达式:\n[\s| ]*\r
匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/
匹配首尾空格的正则表达式:(^\s*)|(\s*$)
匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
匹配网址URL的正则表达式:^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$
匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
匹配国内电话号码:(\d{3}-|\d{4}-)?(\d{8}|\d{7})?
匹配腾讯QQ号:^[1-9]*[1-9][0-9]*$<span> core是unix系统的内核。当你的程序出现内存越界的时候,操作系统会中止你的进程,并将当前内存状态倒出到core文件中,以便进一步分析。程序员可以通过core文件来找出问题所在。它记录了程序挂掉时详细的状态描述。</span>
<span>什么是core dump Core的意思是内存, Dump的意思是扔出来, 堆出来。开发和使用Unix程序时, 有时程序莫名其妙的down了, 却没有任何的提示(有时候会提示core dumped). 这时候可以查看一下有没有形如core.进程号的文件生成, 这个文件便是操作系统把程序down掉时的内存内容扔出来生成的,它可以做为调试程序的参考.
core dump又叫核心转储, 当程序运行过程中发生异常, 程序异常退出时, 由操作系统把程序当前的内存状况存储在一个core文件中, 叫core dump。如何使用core文件 gdb -c core文件路径 [应用程序的路径],进去后输入where回车, 就可以显示程序在哪一行当掉的, 在哪个函数中.</span>
<span>为什么没有core文件生成呢? core文件的生成跟你当前系统的环境设置有关系, 可以用下面的语句设置一下, 然后再运行程序便成生成core文件.</span>
<span>ulimit -c unlimited core文件生成的位置一般于运行程序的路径相同, 文件名一般为core.进程号</span>
top、ps、mv、find、df、cat、chmod、chgrp、grep、wc
1. Advantages of nginx over Apache:
Lightweight, compared to Apache takes up less memory and resources. Highly modular design, writing modules is relatively simple
Anti-concurrency, nginx processes requests asynchronously and non-blockingly, multiple connections (10,000 levels) can correspond to one process, while Apache is blocking and is a synchronous multi-process Model, one connection corresponds to one process. Under high concurrency, nginx can maintain low resources, low consumption and high performance.
2. Apache Advantages over nginx:
Apache’s rewrite is more powerful than nginx’s rewrite, there are many modules, basically everything you can think of can be found, it is relatively stable, there are fewer bugs, nginx has relatively more bugs
CGI
fork a new process to process reading parameters in terms of the process of processing the data. To establish a connection with the process on the remote machine or the local process. To open the tcp port, enter the loop, wait for the arrival of data, and process the data
For example: The server now has 100,000 words. The client will send a string every time and ask how many words are prefixed by this string. Then you can write a program that will build a trie tree, and then you can directly search the trie every time the user requests it. But if you use cgi, the trie will be gone after this request. When the process is started next time, a new trie tree will have to be created. This is too inefficient. With the fastcgi method, the trie tree in this lesson is established when the process starts, and you can directly query the specified prefix on the trie tree later.