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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:03:55+00:00 2026-05-28T06:03:55+00:00

<?php $urls = array( ‘us/1’, ‘us/2’, ‘gb/1’, ‘gb/2’, ‘de/1’, ‘de/2’, ); $current_country = ”;

  • 0
<?php

$urls = array(
    'us/1',
    'us/2',
    'gb/1',
    'gb/2',
    'de/1',
    'de/2',
);

$current_country = '';
foreach ($urls as $url) {
    $sleep_sec = rand(1, 3);
    printf('Proccessed url <b>%s</b> in %s sec%s', strtoupper($url), $sleep_sec, '<br/>');

    $country = substr($url, 0, 2);
    if ($current_country !== $country) {
        $start_at = microtime(true);
        $end_at = microtime(true) - $start_at;

        $logs[] = sprintf('Proccessed country <b>%s</b> in %s sec', strtoupper($country), $end_at);
    }
    $current_country = $country;

    sleep($sleep_sec);
}

echo str_repeat('<br>', 2);

foreach($logs as $log) {
    echo $log;
    echo '<br>';
}

Now result is:

Proccessed url US/1 in 2 sec
Proccessed url US/2 in 2 sec
Proccessed url GB/1 in 1 sec
Proccessed url GB/2 in 2 sec
Proccessed url DE/1 in 3 sec
Proccessed url DE/2 in 2 sec

Proccessed country US in 1.9073486328125E-6 sec
Proccessed country GB in 2.1457672119141E-6 sec
Proccessed country DE in 5.0067901611328E-6 sec

Expected result:

Proccessed country US in 4 sec
Proccessed country GB in 3 sec
Proccessed country DE in 5 sec

How to count correct execution time for each country ?

  • 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-28T06:03:55+00:00Added an answer on May 28, 2026 at 6:03 am

    Move your lines of code around so they actually make sense:

    $start_at = microtime(true);
    foreach ($urls as $url) {
        $sleep_sec = rand(1, 3);
        sleep($sleep_sec);
        printf('Proccessed url <b>%s</b> in %s sec%s', strtoupper($url), $sleep_sec, '<br/>');
    
        $country = substr($url, 0, 2);
        $current_country = $country;
        if ($current_country !== $country) {
            $end_at = microtime(true) - $start_at;
            $logs[] = sprintf('Proccessed country <b>%s</b> in %s sec', strtoupper($country), $end_at);
            $start_at = microtime(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array in PHP with URLs like below: http://example.com/apps/1235554/ http://example.com/apps/apple/ http://example.com/apps/126734 http://example.com/images/a.jpg
I need to parse many html files using php. foreach($url_array as $url){ $file =
Is there a widely accepted class for dealing with URLs in PHP? Things like:
I have a PHP application that will on occasion have to handle URLs where
I have a PHP script that retrieves list of urls from a site and
I have a site with URLs like this: http://domain.co.uk/subdir/page.php I have redesigned the site
How to manually create Friendly URLs? (PHP) So I have created simple php file
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm trying to create tiny urls like this: site.com/abc123 goes to: site.com/index.php?token=abc123 but I

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.