PHP Fatal error: Uncaught HY000 : “Adaptive Server connection timed out”











up vote
0
down vote

favorite












I am running a PHP script to connect to MsSQL and execute a long running stored procedure. That procedure expects an ID which I pass in through this script. I loop over all the ID array and call this procedure. However for some IDs this procedure takes lot of time to run and times out. I set the ATTR_TIMEOUT PDO property to 600s. I have all the PDO statements inside a try catch block. Still, I get this uncaught exception. Here is my sample code: (Please ignore the new_statement params. I used dummies here. Its a valid one and runs fine)



try {
$statement = PDO::new_statement('DB', $sql, 0, false, false, [PDO::ATTR_TIMEOUT => 600]);
$this->execute($statement);
} catch (Exception $e) {
$logger->error("Error for ID: " . $id);
}


This works perfectly for most of the IDs. It fails for some long running IDs. If there is a TIMEOUT issue with executing the query, I would expect the error to be logged. However I see this exception:



PHP Fatal error: Uncaught HY000
["HY000",20003,"Adaptive Server connection timed out [20003] (severity 6)



Could someone please help me with this.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am running a PHP script to connect to MsSQL and execute a long running stored procedure. That procedure expects an ID which I pass in through this script. I loop over all the ID array and call this procedure. However for some IDs this procedure takes lot of time to run and times out. I set the ATTR_TIMEOUT PDO property to 600s. I have all the PDO statements inside a try catch block. Still, I get this uncaught exception. Here is my sample code: (Please ignore the new_statement params. I used dummies here. Its a valid one and runs fine)



    try {
    $statement = PDO::new_statement('DB', $sql, 0, false, false, [PDO::ATTR_TIMEOUT => 600]);
    $this->execute($statement);
    } catch (Exception $e) {
    $logger->error("Error for ID: " . $id);
    }


    This works perfectly for most of the IDs. It fails for some long running IDs. If there is a TIMEOUT issue with executing the query, I would expect the error to be logged. However I see this exception:



    PHP Fatal error: Uncaught HY000
    ["HY000",20003,"Adaptive Server connection timed out [20003] (severity 6)



    Could someone please help me with this.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am running a PHP script to connect to MsSQL and execute a long running stored procedure. That procedure expects an ID which I pass in through this script. I loop over all the ID array and call this procedure. However for some IDs this procedure takes lot of time to run and times out. I set the ATTR_TIMEOUT PDO property to 600s. I have all the PDO statements inside a try catch block. Still, I get this uncaught exception. Here is my sample code: (Please ignore the new_statement params. I used dummies here. Its a valid one and runs fine)



      try {
      $statement = PDO::new_statement('DB', $sql, 0, false, false, [PDO::ATTR_TIMEOUT => 600]);
      $this->execute($statement);
      } catch (Exception $e) {
      $logger->error("Error for ID: " . $id);
      }


      This works perfectly for most of the IDs. It fails for some long running IDs. If there is a TIMEOUT issue with executing the query, I would expect the error to be logged. However I see this exception:



      PHP Fatal error: Uncaught HY000
      ["HY000",20003,"Adaptive Server connection timed out [20003] (severity 6)



      Could someone please help me with this.










      share|improve this question















      I am running a PHP script to connect to MsSQL and execute a long running stored procedure. That procedure expects an ID which I pass in through this script. I loop over all the ID array and call this procedure. However for some IDs this procedure takes lot of time to run and times out. I set the ATTR_TIMEOUT PDO property to 600s. I have all the PDO statements inside a try catch block. Still, I get this uncaught exception. Here is my sample code: (Please ignore the new_statement params. I used dummies here. Its a valid one and runs fine)



      try {
      $statement = PDO::new_statement('DB', $sql, 0, false, false, [PDO::ATTR_TIMEOUT => 600]);
      $this->execute($statement);
      } catch (Exception $e) {
      $logger->error("Error for ID: " . $id);
      }


      This works perfectly for most of the IDs. It fails for some long running IDs. If there is a TIMEOUT issue with executing the query, I would expect the error to be logged. However I see this exception:



      PHP Fatal error: Uncaught HY000
      ["HY000",20003,"Adaptive Server connection timed out [20003] (severity 6)



      Could someone please help me with this.







      php sql-server pdo






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 4:28

























      asked Nov 11 at 4:15









      Sri

      94111




      94111
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Pass the options to the PDO constructor:



          $pdo = new PDO(
          "mysql:host=$host;dbname=$dbname",
          $username,
          $password,
          array(
          PDO::ATTR_TIMEOUT => "(seconds)",
          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
          )
          );


          if that doesn't help, you can try to set connect_timeout manually in php.ini or use ini_set()



          mysql.connect_timeout = "(seconds)"


          If the driver uses sockets for the basic connection, and to set timeouts, you need to use the socket (stream) timeout function



          ini_set("default_socket_timeout", "(seconds)");



          You should also know that




          PDO::ATTR_TIMEOUT: Specifies the timeout duration in seconds. Not all
          drivers support this option, and its meaning may differ from driver to
          driver. For example, sqlite will wait for up to this time value before
          giving up on obtaining an writable lock, but other drivers may
          interpret this as a connect or a read timeout interval.







          share|improve this answer



















          • 1




            Can you explain why you think that this solves the problem? As far as I see, the OP does not use MySQL after all
            – Nico Haase
            Nov 11 at 13:31










          • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
            – tiagoperes
            Nov 11 at 16:51










          • Thank you I will take note.
            – Yaroslaw
            Nov 11 at 17:24










          • Yeah, the timeout works. In fact it waits for 10 minutes and fails. So not sure how to catch this error.
            – Sri
            Nov 11 at 17:27













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245785%2fphp-fatal-error-uncaught-hy000-adaptive-server-connection-timed-out%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          Pass the options to the PDO constructor:



          $pdo = new PDO(
          "mysql:host=$host;dbname=$dbname",
          $username,
          $password,
          array(
          PDO::ATTR_TIMEOUT => "(seconds)",
          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
          )
          );


          if that doesn't help, you can try to set connect_timeout manually in php.ini or use ini_set()



          mysql.connect_timeout = "(seconds)"


          If the driver uses sockets for the basic connection, and to set timeouts, you need to use the socket (stream) timeout function



          ini_set("default_socket_timeout", "(seconds)");



          You should also know that




          PDO::ATTR_TIMEOUT: Specifies the timeout duration in seconds. Not all
          drivers support this option, and its meaning may differ from driver to
          driver. For example, sqlite will wait for up to this time value before
          giving up on obtaining an writable lock, but other drivers may
          interpret this as a connect or a read timeout interval.







          share|improve this answer



















          • 1




            Can you explain why you think that this solves the problem? As far as I see, the OP does not use MySQL after all
            – Nico Haase
            Nov 11 at 13:31










          • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
            – tiagoperes
            Nov 11 at 16:51










          • Thank you I will take note.
            – Yaroslaw
            Nov 11 at 17:24










          • Yeah, the timeout works. In fact it waits for 10 minutes and fails. So not sure how to catch this error.
            – Sri
            Nov 11 at 17:27

















          up vote
          0
          down vote













          Pass the options to the PDO constructor:



          $pdo = new PDO(
          "mysql:host=$host;dbname=$dbname",
          $username,
          $password,
          array(
          PDO::ATTR_TIMEOUT => "(seconds)",
          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
          )
          );


          if that doesn't help, you can try to set connect_timeout manually in php.ini or use ini_set()



          mysql.connect_timeout = "(seconds)"


          If the driver uses sockets for the basic connection, and to set timeouts, you need to use the socket (stream) timeout function



          ini_set("default_socket_timeout", "(seconds)");



          You should also know that




          PDO::ATTR_TIMEOUT: Specifies the timeout duration in seconds. Not all
          drivers support this option, and its meaning may differ from driver to
          driver. For example, sqlite will wait for up to this time value before
          giving up on obtaining an writable lock, but other drivers may
          interpret this as a connect or a read timeout interval.







          share|improve this answer



















          • 1




            Can you explain why you think that this solves the problem? As far as I see, the OP does not use MySQL after all
            – Nico Haase
            Nov 11 at 13:31










          • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
            – tiagoperes
            Nov 11 at 16:51










          • Thank you I will take note.
            – Yaroslaw
            Nov 11 at 17:24










          • Yeah, the timeout works. In fact it waits for 10 minutes and fails. So not sure how to catch this error.
            – Sri
            Nov 11 at 17:27















          up vote
          0
          down vote










          up vote
          0
          down vote









          Pass the options to the PDO constructor:



          $pdo = new PDO(
          "mysql:host=$host;dbname=$dbname",
          $username,
          $password,
          array(
          PDO::ATTR_TIMEOUT => "(seconds)",
          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
          )
          );


          if that doesn't help, you can try to set connect_timeout manually in php.ini or use ini_set()



          mysql.connect_timeout = "(seconds)"


          If the driver uses sockets for the basic connection, and to set timeouts, you need to use the socket (stream) timeout function



          ini_set("default_socket_timeout", "(seconds)");



          You should also know that




          PDO::ATTR_TIMEOUT: Specifies the timeout duration in seconds. Not all
          drivers support this option, and its meaning may differ from driver to
          driver. For example, sqlite will wait for up to this time value before
          giving up on obtaining an writable lock, but other drivers may
          interpret this as a connect or a read timeout interval.







          share|improve this answer














          Pass the options to the PDO constructor:



          $pdo = new PDO(
          "mysql:host=$host;dbname=$dbname",
          $username,
          $password,
          array(
          PDO::ATTR_TIMEOUT => "(seconds)",
          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
          )
          );


          if that doesn't help, you can try to set connect_timeout manually in php.ini or use ini_set()



          mysql.connect_timeout = "(seconds)"


          If the driver uses sockets for the basic connection, and to set timeouts, you need to use the socket (stream) timeout function



          ini_set("default_socket_timeout", "(seconds)");



          You should also know that




          PDO::ATTR_TIMEOUT: Specifies the timeout duration in seconds. Not all
          drivers support this option, and its meaning may differ from driver to
          driver. For example, sqlite will wait for up to this time value before
          giving up on obtaining an writable lock, but other drivers may
          interpret this as a connect or a read timeout interval.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 17:21

























          answered Nov 11 at 8:20









          Yaroslaw

          684




          684








          • 1




            Can you explain why you think that this solves the problem? As far as I see, the OP does not use MySQL after all
            – Nico Haase
            Nov 11 at 13:31










          • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
            – tiagoperes
            Nov 11 at 16:51










          • Thank you I will take note.
            – Yaroslaw
            Nov 11 at 17:24










          • Yeah, the timeout works. In fact it waits for 10 minutes and fails. So not sure how to catch this error.
            – Sri
            Nov 11 at 17:27
















          • 1




            Can you explain why you think that this solves the problem? As far as I see, the OP does not use MySQL after all
            – Nico Haase
            Nov 11 at 13:31










          • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
            – tiagoperes
            Nov 11 at 16:51










          • Thank you I will take note.
            – Yaroslaw
            Nov 11 at 17:24










          • Yeah, the timeout works. In fact it waits for 10 minutes and fails. So not sure how to catch this error.
            – Sri
            Nov 11 at 17:27










          1




          1




          Can you explain why you think that this solves the problem? As far as I see, the OP does not use MySQL after all
          – Nico Haase
          Nov 11 at 13:31




          Can you explain why you think that this solves the problem? As far as I see, the OP does not use MySQL after all
          – Nico Haase
          Nov 11 at 13:31












          This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
          – tiagoperes
          Nov 11 at 16:51




          This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
          – tiagoperes
          Nov 11 at 16:51












          Thank you I will take note.
          – Yaroslaw
          Nov 11 at 17:24




          Thank you I will take note.
          – Yaroslaw
          Nov 11 at 17:24












          Yeah, the timeout works. In fact it waits for 10 minutes and fails. So not sure how to catch this error.
          – Sri
          Nov 11 at 17:27






          Yeah, the timeout works. In fact it waits for 10 minutes and fails. So not sure how to catch this error.
          – Sri
          Nov 11 at 17:27




















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245785%2fphp-fatal-error-uncaught-hy000-adaptive-server-connection-timed-out%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python