0
votes

i want to use this web server in php


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);

and in my index.php is echo function to write a string or other functions but this web server can not run that echo or other php functions and in my localhost i see full withe page and this is my problem where is the problem ?

1

1 Answers

0
votes

There can be several reasons for this error (one of which for example that your web server has not read permissions and thus cannot open the .php files). You could try enabling the php logs and setting your preffered locations and read the error that prevents your code from being displayed.