本文介绍了include / require缓存和fopen不是吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 请帮我解决一个极客论点:)。 我相信php缓存尽可能包含代码。 所以给出了2个文件。 // file.php --- ---------------------------------- <?php $ value =''有些价值''; ?> ----------------- -------------------- // file.txt ----- -------------------------------- 有些价值 ------------------------------------- 如果我试着''使用''两个文件来设置一个值。 --------------------------- ---------- 例A <?php $ value =''''; 包含''file.php''; echo $ value; //''有些价值'' ?> ----------------------- -------------- ------------------------ ------------- 例B <?php $ fd = @fopen(' 'file.txt'',''rb''); $ contents =''''; while(!feof($ fd)){ $ contents。= fread($ fd,8192); } fclose($ fd); echo $内容; //''有些价值'' ?> ----------------------- -------------- 忽略示例A更简单的事实。 这是'真的''示例''将打开文件,(file.php),并仅分配 $值,然后不再读取文件,(除非是 已更改) 。 我在php.exe进程的生命中谈论的,而不是生活中的脚本运行本身的 。 而示例B将每次打开,读取,关闭文件 有页面请求。 您怎么看?是否包括在每个 请求中打开,读取,关闭文件?或者两个文件的内容是否会在 过程中保留? Reagards, FFMG - ''网站管理员论坛''( http://www.httppoint.com )| ''免费博客'' ( http://www.journalhome。 com / )| ''网站管理员目录'' ( http://www.webhostshunter。 com / ) ''娱乐车辆保险'' ( http://www.insurance-owl.com/other/car_rec.php )| ''免费网址 重定向服务''( http://urlkick.com/ ) ------------------------------------- ----------------------------------- FFMG的简介: http://www.httppoint.com/member.php?userid=580 查看以下主题: http://www.httppoint.com/showthread.php?t=22555 通过网站管理员论坛发帖子消息 http://www.httppoint.com ,(广告收益分享)。Hi,Please help me settle a geek argument :).I believe that php caches included code whenever possible.So given the 2 files bellow.// file.php-------------------------------------<?php$value = ''Some value'';?>-------------------------------------// file.txt-------------------------------------Some value-------------------------------------If I try and ''use'' both files to set a value.-------------------------------------EXAMPLE A<?php$value = '''';include ''file.php'';echo $value; // ''Some value''?>--------------------------------------------------------------------------EXAMPLE B<?php$fd = @fopen( ''file.txt'', ''rb'');$contents = '''';while (!feof($fd)) {$contents .= fread($fd, 8192);}fclose($fd);echo $contents; // ''Some value''?>-------------------------------------Ignoring the fact that Example A is simpler.Is it true that ''EXAMPLE A'' will open the file, (file.php), and assign$value only once and then not read the file anymore, (unless it ischanged).I am talking about in the life of the php.exe process, not in the lifeof the script run itself.Whereas EXAMPLE B will open, read, close the file every single timethere is a page request.What do you think? Does include open, read, close the file in everyrequest? Or will the content of both files be kept for the life of theprocess?Reagards,FFMG--''webmaster forum'' (http://www.httppoint.com) | ''Free Blogs''(http://www.journalhome.com/) | ''webmaster Directory''(http://www.webhostshunter.com/)''Recreation Vehicle insurance''(http://www.insurance-owl.com/other/car_rec.php) | ''Free URLredirection service'' (http://urlkick.com/)------------------------------------------------------------------------FFMG''s Profile: http://www.httppoint.com/member.php?userid=580View this thread: http://www.httppoint.com/showthread.php?t=22555Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).推荐答案 value =''有些价值''; ?> ------------ ------------------------- // file.txt ------------------------------------- 有些价值e $> ------------------------------------- 如果我尝试''使用''两个文件来设置一个值。 ------------------ ------------------- 例A <?phpvalue = ''Some value'';?>-------------------------------------// file.txt-------------------------------------Some value-------------------------------------If I try and ''use'' both files to set a value.-------------------------------------EXAMPLE A<?php value =''''; 包含''file.php''; echovalue = '''';include ''file.php'';echo值; //''有些价值'' ?> ----------------------- -------------- ------------------------ ------------- 例B <?phpvalue; // ''Some value''?>--------------------------------------------------------------------------EXAMPLE B<?php 这篇关于include / require缓存和fopen不是吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 17:43