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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:04:06+00:00 2026-05-27T22:04:06+00:00

Basically I have a code: $response = myFunction(); I need to repeat this call

  • 0

Basically I have a code:

 $response = myFunction();

I need to repeat this call if there was an error like this:

do {
   $response = myFunction();

} while ( isset($response['error']) );

But I want to usleep(500); too if there was an error. I could do like this, but I don’t find it so elegant:

do {
   $response = myFunction();

   if (isset($response['error']))
     usleep(500);

} while ( isset($response['error']) );

What Can i do? Maybe something like this (not very elegant neither)

while( isset($response['error']) && !usleep(500) );

Edit

There is another possibility… With the use of goto. But I am always reluctant to goto codes

retry:
$response = myFunction();
if (isset($response['error'])) {
  usleep(500);
  goto retry;
}

To me this seems the most clear and redundancy-free solution. What do you think?

  • 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-27T22:04:06+00:00Added an answer on May 27, 2026 at 10:04 pm
    while (true) {
        $response = myFunction();
    
        if (isset($response['error'])) {
            usleep(500);
        } else {
            break;
        }
    }
    

    Having said that, trying to hammer a function until it returns the correct result may be a sign of a badly thought-out architecture and there may be a better solution for the whole problem to begin with.

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

Sidebar

Related Questions

I have a block of code that basically intializes several classes, but they are
Posted this over at the Drupal forums but haven't received a response. Basically, I
I have a simplified function that looks like this: function(query) { myApi.exec('SomeCommand', function(response) {
I frequently have code that looks something like this: if (itm != null) {
I have this code, which basically looks up an IP address when a user
Basically I have some code to check a specific directory to see if an
I have code running in an iPhone application I am developing. Basically, the code
basically i have (state, state code) pairs, that are subsets of country [USA] ->
I have several Code Analysis CA1704:IdentifiersShouldBeSpelledCorrectly warnings that I want to suppress. Basically, they
i have the following jquery code. basically i will have several overlapped divs and

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.