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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:11:55+00:00 2026-05-31T20:11:55+00:00

foreach ($arr as $k => $v) { $r = my_func($v); $new[$k] = $r; }

  • 0
foreach ($arr as $k => $v)
{
    $r = my_func($v);   

    $new[$k] = $r;
}

How do you do it so that $r will return false if my_func() takes more than 10 secs to execute, else (if it took less than 10 secs) it will return true;

Additional info: my_func() actually reads a URL, sometimes it takes to long. I want it to return false if it takes more than 10 secs.

  • 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-31T20:11:57+00:00Added an answer on May 31, 2026 at 8:11 pm

    You cannot limit execution time by function in PHP. However, do not despair: if as you mentioned your function reads URL, you could use curl extension, which has options set options via curl_setopt, as following:

    CURLOPT_TIMEOUT The maximum number of seconds to allow cURL functions to execute.
    CURLOPT_CONNECTTIMEOUT The number of seconds to wait while trying to connect.

    Using these you could limit the actual time spent on the URL processing with curl.

    You could also use http extension which also allows you to do http connections and has timeout options.

    Finally, you could use context options to file_get_contents:

    $opts = array('http' =>
        array(
            'timeout' => 1.5 // 1.5 seconds
        )
    );
    
    $context = stream_context_create($opts);
    
    $result = file_get_contents('http://example.com/getdata.php', false, $context);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

foreach ($result as $user) { $replacements[$user['Email']] = array( '{FirstName}'=>$user['FirstName'], '{LastName}'=>$user['LastName'], '{Code}'=>$user['RandomCode'] ); } That
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { foreach ($worksheet->getRowIterator() as $row) { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false);
foreach($apps as $app){ echo $this->Form->input('Application', array('type'=>'checkbox', 'id'=>$app['Application']['description'], 'div'=>false,'type'=>'checkbox','value' => $app['Application']['description'],'label'=>$app['Application']['description'])); } <div class=checkboxes> <input
I have a Web Service(.ASMX) code that takes a String Array as a parameter
def recursive_insert(arr) return arr if arr.size<=1 recursive_insert(arr[0,arr.size-1]) i=arr.size-1 while arr[i-1]>arr[i] and i>0 arr[i],arr[i-1] =
I have an array that will be display with pagination. Array ( [0] =>
ArrayList arr = new ArrayList(); string abc = What should I do to convert
How can I search for a key in an array that contains more arrays.
I always wonder why I must write foreach my $x (@arr) instead of foreach
foreach ($_GET as $field => $label) { $datarray[]=$_GET[$field]; echo $_GET[$field]; echo <br>; } print_r($datarray);

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.