4

I'm trying to stream MP4 files through Apache / Nginx using a PHP proxy for authentication. I've implemented byte-ranges to stream for iOS as outlined here: http://mobiforge.com/developing/story/content-delivery-mobile-devices. This works perfectly fine in Chrome and Safari but.... the really odd thing is that if I monitor the server requests to the php page, three of them occur per page load in a browser. Here's a screen shot of Chrome's inspector (going directly to the PHP proxy page):

Chrome inspector

As you can see, the first one gets canceled, the second remains pending, and the third works. Again, the file plays in the browser. I've tried alternate methods of reading the file (readfile, fgets, fread, etc) with the same results. What is causing these three requests and how can I get a single working request?

DeweyOx
  • 719
  • 5
  • 14

2 Answers2

2

The first request is for the first range of bytes, preloading the file. The browser cancels the request once it has downloaded the specified amount.

The second one I'm not sure about...

The third one is when you actually start playing the media file, it requests and downloads the full thing.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
1

Not sure whether this answers your question, but serving large binary files with PHP isn't the right thing to do.

It's better to let PHP handle authentication only and pass the file reference to the web server to serve, freeing up resources.

See also: Caching HTTP responses when they are dynamically created by PHP

It describes in more detail what I would recommend to do.

Community
  • 1
  • 1
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
  • I'm interested in this approach, however do you know if it will work with streaming a file? That is, will it support HTTP_RANGE / HTTP/1.1 206 Partial Content so that users can seek to a specific point in the content? – DeweyOx Oct 05 '12 at 20:18