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 7855553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:25:16+00:00 2026-06-02T20:25:16+00:00

For testing purposes I’d like to build a simple HTTP server in PHP. I

  • 0

For testing purposes I’d like to build a simple HTTP server in PHP.
I know the HTTP headers are terminated by a \r\n on an empty line and I’d like to detect that pattern so I know when my server has received all the headers and can respond to the client.

Even if I also simulate the client like so:

$in = "HEAD / HTTP/1.1\r\n";
$in .= "Host: www.example.com\r\n";
$in .= "Connection: Close\r\n\r\n";
$out = '';

echo "Sending HTTP HEAD request...";
socket_write($socket, $in, strlen($in));

I’m unable to detect the end of the headers. There must be a problem in my thinking logic. Here is my code wich tries to detect the pattern:

do { 
    // read client input 
    $input = socket_read($spawn, 1024, 1) or die("Could not read input\n"); 

    if (preg_match ("/^[\r\n|\r|\n]/", $input)) {
        echo "CRLF detected!!\n";
    } else {
        if (trim($input) != "") { 
            echo "NO CRLF in: ".trim($input)."\n";
        }
    }
} while (true);

I have also tried:

if ($input == "\r\n"){ 

or

if (preg_match ("/[\r\n|\r|\n]{2,}/", $input))

and a lot of other different combinations but none of the options seem to detect the \r\n which indicates the end of the headers.
Any help is much appreciated.

  • 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-02T20:25:18+00:00Added an answer on June 2, 2026 at 8:25 pm

    Thank you Marc B.

    I did not find a solution for this problem.

    The work around I used is:
    – Run a PHP script on your favorite HTTP Server.
    – inspect the $_REQUEST variable and let the script compose a relevant answer using that info
    – Log relevant info/actions to a file.

    This way I’m able to test an App which interacts with a web server. The App connects to my script. I know how the App is interacting with the script by tailing (tail -f) the logfile. The script serves the App with an answer.

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

Sidebar

Related Questions

I would like to implement a simple (testing purposes only) in memory repository as
For testing purposes, let's say input.PHP looks like this <?php { $TO = joe@net.net;
For (JUnit) testing purposes I'd like to make a simple application that would be
Fairly new to MVC3 and I am doing a simple project for testing purposes.
What is largest free datababase for SQL Server engine available for testing purposes?
I would like to create an in-memory database for testing purposes using Derby/JavaDB. I
I'm working on a setup that takes an http request (GET for testing purposes)
I have a simple class (for testing purposes) that I am trying to Query
For testing purposes, I'm looking for a simple way to start a standalone JNDI
For testing purposes, I placed two databases on the same server, I want to

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.