php - Redo last foreach loop command on specific condition -


we making request webservice 1000 times. each time make request expect response, webservice fails , provides no response. when happens sleep 30 seconds, , re-run loop @ last point failed. how can done?

here's basic structure:

foreach ( $objects $object ) {     foreach ( $otherobjects $otherobject ) {          //prepare request data $object , $otherobjects          //send request webservice using curl          //receive response , check see if success         if ( isset( $response ) ) {             //save response database         } else {             //not successful. sleep 30 seconds. send request again 3 times. if successful continue, if not break , alert system admin.         }     } } 

you might break request off function:

foreach ( $objects $object ) {     foreach ( $otherobjects $otherobject ) {         $tries = 0;         //receive response , check see if success.         while( ($response = dorequest($object, $otherobject)) === false && $tries < 3) {             //not successful. sleep 30 seconds. send request again 3 times.             $tries++;             sleep(30);         }         if ( $response ) {             //successful save response database.         } else {             //not successful break , alert system admin.     } }  function dorequest($object, $otherobject) {     //prepare request data $object , $otherobject.     //send request webservice using curl.      return $result; } 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -