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

  • Home
  • SEARCH
  • 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 6212773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:34:39+00:00 2026-05-24T06:34:39+00:00

Consider the following scenario: http://www.restserver.com/example.php returns some content that I want to work with

  • 0

Consider the following scenario:

  • http://www.restserver.com/example.php returns some content that I want to work with in my web-application.

  • I don’t want to load it using ajax (SEO issues etc.)

  • My page takes 100ms to generate, the REST resource also takes 100ms to be loaded.

  • We assume that the 100ms generation time of my website occour before I begin working with the REST resource. What comes after that can be neglected.

Example Code:

Index.php of my website

<?
do_some_heavy_mysql_stuff(); // takes 100 ms
get_rest_resource(); // takes 100 ms
render_html_with_data_from_mysql_and_rest(); // takes neglectable amount of time
?>

Website will take ~200ms to generate.

I want to turn this into:

<?
Restclient::initiate_rest_loading(); // takes 0ms
do_some_heavy_mysql_stuff(); // takes 100 ms
Restclient::get_rest_resource(); // takes 0 ms because 100 ms have already passed since initiation
render_html_with_data_from_mysql_and_rest(); // takes neglectable amount of time
?>

Website will take ~100ms to generate.

To accomplis this I thought about using something like this:

(I am pretty sure this code will not work because this question is all about asking how to accomplish this, and whether its possible. I just thought some naive code could demonstrate it best)

class Restclient {
    public static $buffer;
    public static function initiate_rest_loading() {
        // open resource
        $handle = fopen ("http://www.restserver.com/example.php", "r");
        // set to non blocking so fgets will return immediately
        stream_set_blocking($handle,0);
        // initate loading, but return immediately to continue website generation
        fgets($handle, 40960);
    }
    public static function get_rest_resource() {
        // set stream to blocking again because now we really want the data
        stream_set_blocking($handle,1);
        // get the data and save it so templates can work with it
        self::$buffer = fgets($handle, 40960); templates
    }
}

So final question:

  • Is this possible and how?

  • What do I have to keep an eye on (internal buffer overflows, stream lengths etc.)

  • Are there better methods?

  • Does this well work with http resources?

  • Any input is appriciated!

I hope I explained it understandable. If anything is unclear, please leave a comment, so I can rephrase it!

  • 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-05-24T06:34:41+00:00Added an answer on May 24, 2026 at 6:34 am

    As “any input is appreciated”, here is mine:

    • What you want is called asynchronous (you want to something while something else is being done “in the background”).

    To solve your problem, I thought on this:

    1. Separate do_some_heavy_mysql_stuff and get_rest_resource in two different PHP scripts.

    2. Use cURL “multi” ability to do simultaneous requests. Please, check:

      • curl_multi_init and related PHP functions
      • Simultaneous HTTP requests in PHP with cURL

    This way, you can perform both scripts at the same time. Using cURL multi features, you can call http://example.com/do_some_heavy_mysql_stuff.php and http://example.com/get_rest_resource.php at the same time, and then play with the results as soon as they’re available.

    These are my first thoughts, and Iim sharing them with you. Maybe there are different and more interesting approaches… Good luck!

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

Sidebar

Related Questions

Consider the following scenario: http://www.yourdomain.com/Default.aspx?p=2 Now we ofcourse want to check if the querystring
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the following scenario: I own www.a.com , and in my index page I
please consider the following scenario for .net 2.0: I have an event that is
I'm trying to improve my coding style. Consider the following scenario: Suppose that I
Consider the following scenario: Page written in classic ASP or PHP, which is rendering
Please consider the following scenario: map(T,S*) & GetMap(); //Forward decleration map(T, S*) T2pS =
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider the following scenario: Tables: Employee (EmpId(PK), Name) TeamMembers(TeamId(PK), EmpId(PK)) Project(ProjId(PK), TeamId) I really
Consider the following scenario which I'm due to find myself in shortly: You're 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.