Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:57:37+00:00 2026-06-07T05:57:37+00:00

I just tried this code: <?php set_time_limit(0); $address = ‘176.9.117.136’; $port = 9000; $sock

  • 0

I just tried this code:

<?php
set_time_limit(0);

$address = '176.9.117.136';
$port = 9000;

$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, $address, $port) or die('Could not bind to address');

while(1)
{
    socket_listen($sock);
    $client = socket_accept($sock);

    $input = socket_read($client, 1024);
    echo $input;

    $output = 'URL: http://ip-of-my-server:9000/
HTTP/1.1 200 OK
Date: Tue, 10 Jul 2012 16:58:23 GMT
Server: TestServer/1.0.0 (PHPServ)
Last-Modified: Fri, 06 Jul 2012 14:29:58 GMT
ETag: "13c008e-1b9-4c42a193de580"
Accept-Ranges: bytes
Content-Length: 441
Vary: Accept-Encoding
Content-Type: text/html

';
    socket_write($client, $output);

    socket_close($client);
}

socket_close($sock);
?>

But there is a problem. Instead of using the content of $output as the headers, Apache returns its own headers…

I don’t know why because I execute the script via this command: php webserv.php.

However it practically works, because when I load the page http://ip-of-my-server:9000/ from my browser, it shows me the headers sent by the client on the server, and returns the content of $output to the client (my browser).

I want to create my own webserver only in PHP if it’s possible. I just want to know how to run it without Apache, so I can manage my own HTTP headers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:57:39+00:00Added an answer on June 7, 2026 at 5:57 am

    Is there a reason to implement an HTTP server in PHP (of all things)? There’s no threading, etc. It would be a pain… (unless this is some sort of academic thing…)

    PHP 5.4 ships with a built-in webserver. Maybe that is what you’re looking for…


    Update:

    While I understand your motivation to learn this sort of stuff, I believe you’re on the wrong track trying this sort of stuff with PHP. PHP is not really designed for long running processes (like a server would be), it is not equipped for parallel processing (threads). Even multi-processing would require PCNTL, specifically pcntl_fork() and limit your educational walkabout to a Unix based system (which may not be a problem, though).

    If your goal is to understand how servers deal with concurrency, I suggest playing with a language designed for that (Erlang, Go, Scala, …). Or play with a language that at least sort of emulates parallel processing (Python, Ruby, … [sort of, because of their GILs]).

    If your goal is to understand HTTP (and let me tell you HTTP is a beast, if you’re going past HTTP/1.0 and want to do it right), fiddling with PHP may be fine, if it’s the only language you’re firm in. If so, have a look at the example code (chat server) in this (sadly German) article on Socket Servers in PHP to get the basic socket stuff running an concentrate on the actual HTTP.


    Update 2:

    To answer your question regarding the headers…
    I have no clue how apache would fit into the scenario described in your question. But I see you’re using line-breaks to delimit headers and a double line-break to delimit headers from body. Unless you’ve saved your php file using \r\n as the default line-break (windows-style), you’re header-part is malformed and would thus be recognized as the body. Depending on the http client (user agent, may it be your browser, or curl, or whatever) this may be treated with "insert some default headers". Replace your line-breaks with \r\n and try again.

    If your server is reachable from the internet, try some header test tools to verify your HTTP is sound. If it is localhost-only, see what curl -I http://ip-of-my-server:9000 spits out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is just some pretty standard code I have tried. What I am trying
I just tried the tooltip like this Easy image preview ... But i cant
I just tried to run my test app and I got this error: 2012-06-16
hope this will be a quick easy question, I've just tried my app on
I have tried troubleshooting this problem and just ended up with nothing, I hope
I tried doing this: [toolbar setTint:[UIColor colorWithPatternImage:[UIImage imageNamed:@thingFromMyBundle.png]]]; but it just ended up black.
I tried something like this but it just makes the background of the image
Input: $string = this-is-just-an--example Output: this is just an-example Tried various things centered around
I tried to load my Array s like this, but it loads just first
The code is like this: <SCRIPT LANGUAGE=JavaScript> function showReview(){ //javascript stuff <?php $http=obj.href ='http://localhost/PROJECT1/thispage.php';

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.