Support the ongoing development of Laravel.io →
Requests Testing

as a test, i'd like to respond to a resource request, say mp4, in 5 seconds to 1 minutes deliberately. what i have in my mind is sleep() and then return Redirect::to() or Response::make() in a controller. what are your thoughts?

will there be a better way like modifying web server(apache or nginix conf)?

there are many delay point in between req and response. access network(wifi or cellular), backhaul(the network line infra), and the server. what i want to do is simulate the third one, and want to test/implement how and what client should act. this is critical for the mobile app dev guy like me, and mobile apps heavily depend on http data apis provided by a server code, and mobile apps which downloads server resources whatever it is video, audio(buffer based and range request), or just file(chuncked encoding)

if there's anyone wants to know what i did for first and second, leave a comment saying so.

thanks in advance for sharing your knowledges.

Last updated 3 years ago.
0

let me study more tomorrow and elaborate more on the question thread. on my second thought what i want was not a delay in 301 response. what i really want was real resource, say video/mp4 after routes.php's 301.

Last updated 3 years ago.
0

If the goal is waiting on a response from a 3rd party service or stream there are lots of ways to do it without sleeping.

The most commonly used method for this is using event listeners usually on state changes.

This is very common in Ajax loading and looks something like this.

var my_request = new XMLHttpRequest();

//create a function that fires each time the request state changes
my_request.onreadystatechange = function()
{
    // check to see if the state of the request is ready and valid
    if (this.readyState == 4 && this.status == 200) 
    {
        var response = this.responseText;
        alert(response);
    }
}
my_request.open("get", "http://localhost/", true);
my_request.send()

You can also do this with CURL in php..... I am not sure if this is what you are needing though.

Last updated 3 years ago.
0

I end up doing like DrPrez's recommendation, sleep(). I'll have to keep studying how to throttle the actual resource response at server side.

Last updated 3 years ago.
0

Thanks for your idea. I think you meant setTimeOut in if test block. What I want was delay in server side, not in client side. Anyway thanks a lot.

IanSirkit said:

Last updated 3 years ago.
0

Update: I was not good at what I wanted to. I should have titled this as 'Throttle response throughput' or something. Anyway I found a solution and made it through nginix config. Thanks community.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

appkr appkr Joined 20 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.