{"id":321037,"date":"2021-02-05T09:44:22","date_gmt":"2021-02-05T01:44:22","guid":{"rendered":"http:\/\/4563.org\/?p=321037"},"modified":"2021-02-05T09:44:22","modified_gmt":"2021-02-05T01:44:22","slug":"php-%e5%81%9a%e6%95%b0%e6%8d%ae%e7%bc%93%e5%ad%98%e6%97%b6%e9%81%87%e5%88%b0%e4%b8%80%e4%b8%aa%e4%b8%8d%e5%81%9c%e5%86%99%e5%85%a5%e7%bc%93%e5%ad%98%e7%9a%84%e9%97%ae%e9%a2%98%ef%bc%8c%e8%af%a5","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=321037","title":{"rendered":"PHP \u505a\u6570\u636e\u7f13\u5b58\u65f6\u9047\u5230\u4e00\u4e2a\u4e0d\u505c\u5199\u5165\u7f13\u5b58\u7684\u95ee\u9898\uff0c\u8be5\u600e\u4e48\u89e3\u51b3\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  PHP \u505a\u6570\u636e\u7f13\u5b58\u65f6\u9047\u5230\u4e00\u4e2a\u4e0d\u505c\u5199\u5165\u7f13\u5b58\u7684\u95ee\u9898\uff0c\u8be5\u600e\u4e48\u89e3\u51b3\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : frozenway <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>\/\/\u83b7\u53d6\u7f13\u5b58         $tmp = unserialize(file_get_contents('tmp.txt'));         \/\/\u5f97\u5230\u4ee5\u4e0b\u7f13\u5b58\u6570\u7ec4         $tmp = [             'a' =&gt; 'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq',             'b' =&gt; 'wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww',             'c' =&gt; 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',             'd' =&gt; 'rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr',             'e' =&gt; 'tttttttttttttttttttttttttttttttttttttttttt',             'f' =&gt; 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',             'g' =&gt; 'uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu',             'h' =&gt; 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii',             ...         ];         \/\/\u66f4\u65b0\u7f13\u5b58         $tmp['b'] = 'ooooooooooooooooooooooooooooooooooooooooo';         file_put_contents('tmp.txt', serialize($tmp));         \/\/\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u591a\u4e2a\u7ebf\u7a0b\u5728\u8bfb\u53d6\u8fd9\u4e2a\u7f13\u5b58\u7684\u65f6\u5019         \/\/\u5f53\u7ebf\u7a0b A \u5728\u66f4\u65b0\u7f13\u5b58\u65f6,\u8c03\u7528\u4ee5\u4e0b\u65b9\u6cd5         $tmp['a'] = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';         file_put_contents('tmp.txt', serialize($tmp));         \/\/\u800c\u5728\u7ebf\u7a0b A \u66f4\u65b0\u7f13\u5b58\u7684\u540c\u65f6\uff0c\u7ebf\u7a0b B \u5728\u8bfb\u53d6 tmp \u8fd9\u4e2a\u7f13\u5b58         $tmp = unserialize(file_get_contents('tmp.txt'));         \/\/\u5047\u8bbe A \u7ebf\u7a0b\u6267\u884c\u66f4\u65b0\u7f13\u5b58\u65f6\uff0c\u6587\u4ef6\u5185\u5bb9\u521a\u5199\u5165\u4e00\u90e8\u5206,\u90a3\u4e48\u7ebf\u7a0b B \u8bfb\u53d6\u51fa\u6765\u7684         \/\/\u7f13\u5b58\u6570\u636e\u662f         $tmp = false;         \/\/\u90a3\u4e48\u7ebf\u7a0b B \u5c31\u4f1a\u67e5\u6570\u636e\u5e93\u540e\u5f97\u5230\u6570\u636e\u540e\u5199\u5165\u7f13\u5b58         $tmp['b'] = 'ssssssssssssssssssssssssssssssssssssssss';         file_put_contents('tmp.txt', serialize($tmp));         \/\/\u7136\u540e\u6700\u7ec8\u7684\u95ee\u9898\u6765\u4e86         \/\/\u5982\u679c\u8bbe\u7f6e\u8fd9\u4e2a\u7f13\u5b58\u6570\u636e\u6709\u6548\u671f 1 \u5c0f\u65f6\uff0c         \/\/\u5f53\u51e0\u5341\u4e0a\u767e\u4e2a\u7ebf\u7a0b\u9891\u7e41\u8bbf\u95ee\u8fd9\u4e2a\u7f13\u5b58\u6570\u636e,\u5982\u679c\u4e0d\u5b58\u5728\u5176\u4e2d\u7684 a \u6216 b \u6216\u5176\u4ed6\u952e\u7684\u503c\uff0c\u5c31         $tmp['x'] = '......................................'; \/\/x \u4e3a abcdefg..\u7684\u4e4b\u4e2d\u4e00\u4e2a\u952e         file_put_contents('tmp.txt', serialize($tmp));         \/\/\u5982\u679c\u66f4\u65b0\u5176\u4e2d\u4e00\u4e2a\u952e\u7684\u503c\u65f6\uff0c\u521a\u5199\u5165\u4e00\u90e8\u5206\u5230 tmp.txt,\u90a3\u4e48\u5176\u4ed6\u7ebf\u7a0b\u8bfb\u53d6         \/\/\u7f13\u5b58\u65f6\u5f97\u5230\u7684\u503c\u662f false,\u90a3\u4e48\u53c8\u5404\u81ea\u66f4\u65b0\u5199\u5165\u81ea\u5df1\u7684\u7f13\u5b58         \/\/\u8fd9\u4e48\u4e00\u6765\uff0c\u53ea\u8981\u6709\u4e00\u4e2a\u8fdb\u7a0b\u66f4\u65b0\u5199\u5165\u5230 tmp.txt \u6587\u4ef6\u800c\u8fd8\u6ca1\u5168\u90e8\u5199\u5b8c\u65f6\uff0c\u53e6\u4e00\u7ebf\u7a0b\u5c31         \/\/\u8bfb\u53d6\uff0c\u5c31\u4f1a\u9020\u6210\u6e05\u7a7a\u4e86\u6240\u6709\u7f13\u5b58\u7684\u60c5\u51b5\uff0c\u6700\u540e\u9020\u6210\u8fd9\u4e2a tmp \u7f13\u5b58\u88ab\u4e0d\u505c\u6e05\u7a7a\u53c8\u4e0d\u505c\u5199\u5165         \/\/\u8fd9\u5c31\u7f13\u5b58\u7684\u4f7f\u7528\u76ee\u7684\u4e86         \/\/\u8fd9\u79cd\u60c5\u51b5\u8be5\u600e\u4e48\u89e3\u51b3 <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>12<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5020312\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chaodada <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u52a0\u9501\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020313\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Makoto <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7f13\u5b58\u8bfb\u7684\u65f6\u5019\u65e0\u9650\u5236\uff0c\u5199\u4e4b\u524d\u68c0\u67e5 \/\u52a0\u9501\uff0c\u6bcf\u6b21\u53ea\u5141\u8bb8\u4e00\u4e2a\u7ebf\u7a0b\u5199                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020314\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : setsunakute <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u52a0\u9501 \u53ef\u4ee5\u7528 flock \u51fd\u6570<br \/>https:\/\/www.php.net\/manual\/zh\/function.flock.php                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020315\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sagaxu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5199\u4e34\u65f6\u6587\u4ef6\u518d rename \u8fc7\u53bb\uff0crename \u662f\u539f\u5b50\u64cd\u4f5c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020316\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lovecy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u591a\u8fdb\u7a0b\u6761\u4ef6\u4e0b\u4fdd\u6301\u552f\u4e00\u6027\u7d2f\u4e0d\u7d2f\u554a\u3002\u3002<br \/>1. \u7528\u4e00\u4e2a\u5b9a\u65f6\u8fdb\u7a0b\u53bb\u5237\u65b0\u7f13\u5b58\u6587\u4ef6<br \/>2. \u7528\u4e00\u4e2a\u5e38\u9a7b\u8fdb\u7a0b\u53bb\u5904\u7406\u6240\u6709\u7684\u7f13\u5b58\u8bfb\u53d6\u64cd\u4f5c\uff08\u5bf9\uff0c\u5c31\u662f\u8ba9\u4f60\u4e0a Redis \uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020317\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : emeab <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7f13\u5b58\u96ea\u5d29 \u52a0\u9501\u628a.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020318\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : frozenway <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Makoto @setsunakute @sagaxu @lovecy \u6211\u73b0\u5728\u7528\u7684\u662f thinkphp5.1 \u7684 cache \u7684 file \u6a21\u5f0f\u53bb\u5199\u7f13\u5b58\uff0c\u770b\u4e86\u6e90\u4ee3\u7801\uff0c\u4e5f\u5b58\u5728\u8fd9\u79cd\u60c5\u51b5\uff0c\u597d\u65e0\u52a9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020319\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : frozenway <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             TP5.1 \u7684<br \/>&#8220;`<br \/>\/**<br \/> * \u8bfb\u53d6\u7f13\u5b58<br \/> * @access public<br \/> * @param string $name \u7f13\u5b58\u53d8\u91cf\u540d<br \/> * @param mixed $default \u9ed8\u8ba4\u503c<br \/> * @return mixed<br \/> *\/<br \/> public function get($name, $default = false)<br \/> {<br \/> $this-&gt;readTimes++;<\/p>\n<p> $filename = $this-&gt;getCacheKey($name);<\/p>\n<p> if (!is_file($filename)) {<br \/> return $default;<br \/> }<\/p>\n<p> $content = file_get_contents($filename);<br \/> $this-&gt;expire = null;<\/p>\n<p> if (false !== $content) {<br \/> $expire = (int) substr($content, 8, 12);<br \/> if (0 != $expire &amp;&amp; time() &gt; filemtime($filename) + $expire) {<br \/> \/\/\u7f13\u5b58\u8fc7\u671f\u5220\u9664\u7f13\u5b58\u6587\u4ef6<br \/> $this-&gt;unlink($filename);<br \/> return $default;<br \/> }<\/p>\n<p> $this-&gt;expire = $expire;<br \/> $content = substr($content, 32);<\/p>\n<p> if ($this-&gt;options[&#8216;data_compress&#8217;] &amp;&amp; function_exists(&#8216;gzcompress&#8217;)) {<br \/> \/\/\u542f\u7528\u6570\u636e\u538b\u7f29<br \/> $content = gzuncompress($content);<br \/> }<br \/> return $this-&gt;unserialize($content);<br \/> } else {<br \/> return $default;<br \/> }<br \/> }<\/p>\n<p> \/**<br \/> * \u5199\u5165\u7f13\u5b58<br \/> * @access public<br \/> * @param string $name \u7f13\u5b58\u53d8\u91cf\u540d<br \/> * @param mixed $value \u5b58\u50a8\u6570\u636e<br \/> * @param int|DateTime $expire \u6709\u6548\u65f6\u95f4 0 \u4e3a\u6c38\u4e45<br \/> * @return boolean<br \/> *\/<br \/> public function set($name, $value, $expire = null)<br \/> {<br \/> $this-&gt;writeTimes++;<\/p>\n<p> if (is_null($expire)) {<br \/> $expire = $this-&gt;options[&#8216;expire&#8217;];<br \/> }<\/p>\n<p> $expire = $this-&gt;getExpireTime($expire);<br \/> $filename = $this-&gt;getCacheKey($name, true);<\/p>\n<p> if ($this-&gt;tag &amp;&amp; !is_file($filename)) {<br \/> $first = true;<br \/> }<\/p>\n<p> $data = $this-&gt;serialize($value);<\/p>\n<p> if ($this-&gt;options[&#8216;data_compress&#8217;] &amp;&amp; function_exists(&#8216;gzcompress&#8217;)) {<br \/> \/\/\u6570\u636e\u538b\u7f29<br \/> $data = gzcompress($data, 3);<br \/> }<\/p>\n<p> $data = &#8220;&lt;?phpn\/\/&#8221; . sprintf(&#8216;%012d&#8217;, $expire) . &#8220;n exit();?&gt;n&#8221; . $data;<br \/> $result = file_put_contents($filename, $data);<\/p>\n<p> if ($result) {<br \/> isset($first) &amp;&amp; $this-&gt;setTagItem($filename);<br \/>  clearstatcache();<br \/> return true;<br \/> } else {<br \/> return false;<br \/> }<br \/> }<br \/>&#8220;`<br \/>\u4e5f\u6ca1\u52a0\u9501\uff0c\u4f1a\u4e0d\u4f1a\u4e5f\u6709\u95ee\u9898\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020320\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzhpeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e00\u4e0b\u7ebf\u7a0b\uff0c\u4e00\u4e0b\u8fdb\u7a0b\uff0c\u641e\u61f5\u4e86\uff0cfpm \u6a21\u5f0f\u4e0d\u5c31\u662f\u591a\u8fdb\u7a0b\u5355\u7ebf\u7a0b\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020321\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wangritian <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6700\u4f73\u89e3\u51b3\u65b9\u6848\uff1aredis                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020322\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzhpeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd8\u6709\uff0c\u4e3a\u4ec0\u4e48\u8fd9\u6837\u8bbe\u8ba1\u5462\uff1f\u6570\u7ec4\u5e8f\u5217\u5316\u5b58\u50a8\uff0c\u53cd\u5e8f\u5217\u5316\u66f4\u65b0\u3002string \u5b58\u50a8\u4e0d\u5c31\u597d\u4e86\uff0c\u72ec\u7acb\u5f00\u6765\u3002\u6848\u4f8b\u6765\u770b\uff0c\u4f60\u7684\u6570\u636e\u72ec\u7acb\u6027\u633a\u5f3a\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5020323\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e00\u4e2a key \u4e00\u4e2a\u6587\u4ef6\u4e0d\u597d\u4e48\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u505a\u6570\u636e\u7f13\u5b58\u65f6\u9047\u5230\u4e00\u4e2a\u4e0d\u505c\u5199&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/321037"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=321037"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/321037\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321037"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}