Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php web服务器无法读取php文件_Php - Fatal编程技术网

php web服务器无法读取php文件

php web服务器无法读取php文件,php,Php,我想在php中使用这个web服务器 set_time_limit(0); $address = '127.0.0.1'; $port = 80; $sock = socket_create(AF_INET, SOCK_STREAM, 0); socket_bind($sock, $address, $port) or die('Could not bind to address'); echo "\n Listening On port $port For Connection... \n

我想在php中使用这个web服务器

set_time_limit(0); $address = '127.0.0.1'; $port = 80; $sock = socket_create(AF_INET, SOCK_STREAM, 0); socket_bind($sock, $address, $port) or die('Could not bind to address'); echo "\n Listening On port $port For Connection... \n\n"; while(1) { socket_listen($sock); $client = socket_accept($sock); $input = socket_read($client, 1024); $incoming = array(); $incoming = explode("\r\n", $input); $fetchArray = array(); $fetchArray = explode(" ", $incoming[0]); $file = $fetchArray[1]; if($file == "/"){ $file = "index.php"; } else { $filearray = array(); $filearray = explode("/", $file); $file = $filearray[1]; } echo $fetchArray[0] . " Request " . $file . "\n"; $output = ""; $Header = "HTTP/1.1 200 OK \r\n" . "Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" . "Content-Type: text/html \r\n\r\n"; $Content = file_get_contents($file); $output = $Header . $Content; socket_write($client,$output,strlen($output)); socket_close($client);
在我的index.php中,echo函数用于编写字符串或其他函数,但此web服务器无法运行echo或其他php函数。在我的本地主机中,我看到了完整的withe页面,这就是我的问题。问题出在哪里?

此错误可能有几个原因,例如,您的web服务器没有读取权限,因此无法打开.php文件。您可以尝试读取阻止显示代码的错误。

没有权限错误。index.php在控制台上运行true,但无法在上的localhost上运行browser@user3748360事实并非如此。在控制台上,用户是您,而在Web服务器上,用户是apache。显然,您可以r/w/x文件,但是apache能够吗?您的文件的权限是什么?您是否已将这些文件的所有权授予apache?@sestus询问者使用的服务器不是apache。@Jim是的,您是对的。我刚刚举了一个例子,apache是一个主流,所以它刚刚问世。我想展示一下原则。无论如何,我建议的解决方法是检查php日志。