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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:01:03+00:00 2026-06-04T03:01:03+00:00

Is there a way to timeout a function? I have 10 minutes to perform

  • 0

Is there a way to timeout a function? I have 10 minutes to perform a job. The job includes a for loop, here is an example:

<?php
foreach($arr as $key => $value){
   some_function($key, $value); //This function does SSH and SFTP stuff
}
?>

$arr has 15 elements and some_function() sometimes may take more than 1 minutes. In fact once it got hanged for 5 minutes.

Is there a way I can timeout the function call and move on with next element in $arr?

Thank you!!

  • 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-06-04T03:01:04+00:00Added an answer on June 4, 2026 at 3:01 am

    It depends on your implementation. 99% of the functions in PHP are blocking. Meaning processing will not continue until the current function has completed. However, if the function contains a loop you can add in your own code to interrupt the loop after a certain condition has been met.

    Something like this:

    foreach ($array as $value) {
      perform_task($value);
    }
    
    function perform_task($value) {
      $start_time = time();
    
      while(true) {
        if ((time() - $start_time) > 300) {
          return false; // timeout, function took longer than 300 seconds
        }
        // Other processing
      }
    }
    

    Another example where interrupting the processing IS NOT possible:

    foreach ($array as $value) {
      perform_task($value);
    }
    
    function perform_task($value) {
        // preg_replace is a blocking function
        // There's no way to break out of it after a certain amount of time.
        return preg_replace('/pattern/', 'replace', $value);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to automatically restart Selenium grid on a timeout? When one
I have am writing a Python function that takes a timeout value as a
I have an application secured with devise and a session timeout of 30 minutes.
is there way how to get name ov event from Lambda expression like with
Is there way to better identify design pattern in source codes, esp. if you
Is there way to mute an audio stream or at least control the volume?
Is there way to set @include mixin(); to variable? I tried this @mixin bg-gradient($fallback,
Is there way that I can read the file from remote server using fopen
Is there a way you can add a column to the Details view of
Is there a way to return a random row from a table using LINQToSQL?

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.