X
X
x9h6qbpzdxktxao1uw2021-06-08 02:21:54
PHP
x9h6qbpzdxktxao1uw, 2021-06-08 02:21:54

How to stop an infinite loop in php?

Tell me what's wrong :(

function allServers() {
    return [
      [
       'host' => '127.0.0.1',
       'username' => 'root',
       'pass' => 'root'
      ],
      [
       'host' => '127.0.0.1',
       'username' => 'root',
       'pass' => 'root'
      ],
    ];
  }

case '/updateproxy': {

          $allserver = allServers();
          
          $good = 0;
          for ($i = 0, $size = count($allserver); $i < $size; ++$i) {
            $connection = ssh2_connect($allserver[$i]['host'], 22);
            if (ssh2_auth_password($connection, $allserver[$i]['username'], $allserver[$i]['pass'])) {
              $stream = ssh2_exec($connection, 'cd /root/1; sh proxy.sh;');
            } else {
              $good++;
              break;
            } 
          }
          
          if ($good != 0){
            botSend([
            ' На каком то из сервером возникла ошибка!',
            ], chatAdmin());
            break;
          }
          
          $result = [' Прокси успешно обновлены!',];
          
          botSend([
            ' Прокси успешно обновлены!',
          ], chatAlerts());

          $flag = true;
          break;
        }

In case of success, everything is fine, in case of an error:
image.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lev Zabudkin, 2021-06-08
@zabudkin

And if you change
for ($i = 0, $size = count($allserver); $i < $size; ++$i) {
to
for ($i = 0; $i < count($allserver); $i++ ) {
then what is the result? ;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question