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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:22:13+00:00 2026-06-02T08:22:13+00:00

With PHP and Apache, is it possible to start the PHP script after the

  • 0

With PHP and Apache, is it possible to start the PHP script after the headers are received, but before the body is sent ?

I mean kind of this:

PUT /sync/testStream.php HTTP/1.1
Host: localhost
User-Agent: test
Content-Length: 500
Content-Type: text/plain

<start the script here>

hello
this is a test

The objective is to lock a file during the script (during its upload actually).

I tried to read from php://input, with no success: the script is started only when the whole body is received.

Here is my script:

<?php
echo "Hello. Start sending data.";
ob_flush();

$file = fopen('php://input', 'r');
if ($file === false) {
    die("Could not open php://input");
}

while (($line = fgets($file)) !== false) {
    echo $line;
}

echo "Bye";

Any hint is welcome !

  • 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-02T08:22:19+00:00Added an answer on June 2, 2026 at 8:22 am

    I have seen this question on here before (can’t find it right now, but I have) and after much discussion/debate, that conclusion was that No, you can’t.

    This is because the file upload process and receiving of the body of the request is handled by the overlying web server, and PHP is not fired up until after the request has been fully received/parsed/validated.

    One point here is that your script appears to be attempting to establish full-duplex communication over HTTP, which is not possible. HTTP is by it’s very nature a half-duplex protocol – it has a request-response architecture and you cannot start sending a response before you have completely received the request, it would be a protocol violation.

    If you explain exactly what you are trying to do/why you want to lock a file during upload, maybe we can find an alternative solution.

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

Sidebar

Related Questions

Is it possible to re-write (Apache Mod-Rewrite) a URL from this: http://www.example.com/view.php?t=h5k6 to this
Is it possible to deny from all apache htaccess style using php. I can't
I need to monitor HTTP traffic in my dev env which is PHP/Apache/Windows. But
How can I setup expires headers in PHP + Apache? I'm currently using an
I'm running PHP with Apache locally on my PC on Windows. The script uploads
I have a Windows/Apache/PHP environment set up to imitate a shared hosting account but
This might not be a programming question but I am posting it after long
Is it possible for PHP to read/parse the current vhosts' Apache VirtualHost config block,
I have written a PHP Script, I run the code like this on MS-DOS
Is it possible with PHP(5) or other Linux tools on an apache debian webserver

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.