Jump to content

Recommended Posts

For instance, if used in the following fictional script, they might be created and remain active for months at a time.  Is there any  concern about memory never being released, or anything other to watch out for?  Is this approach okay, or is one better creating the prepared statement, doing the work, and then closing it typical for most http request?

 

Thanks

$stmtSelect=$this->pdo->prepare('SELECT a, b, c FROM table_1 WHERE d=?');
$stmtInsert=$this->pdo->prepare('INSERT INTO table_1(a, b, c, d) VALUES(?,?,?,?)');
$stmtUpdate=$this->pdo->prepare('UPDATE table_1 SET a=?, b=?, c=? WHERE d=?');

$socket->on('connection', function (ConnectionInterface $conn) use($stmtSelect, $stmtInsert, $stmtUpdate) {
    $conn->on('data', function ($data) use ($conn) use($stmtSelect, $stmtInsert, $stmtUpdate) {
       $d=doSomething($data);
       if(someCondition) {
          $stmtSelect->execute([$d->a,$d->b,$d->c,$d->d]);
       }
       elseif(someOtherCondition{
           $stmtInsert->execute([$d->a,$d->b,$d->c,$d->d]);
       }
       else {
           $stmtUpdate->execute([$d->a,$d->b,$d->c,$d->d]);
       }
   });
});


//Script never gets here and it runs forever...

 

Link to comment
https://forums.phpfreaks.com/topic/305899-do-prepared-statements-expire/
Share on other sites

They will be used, but just not on every on data event.  The select query will happen often (potentially several times per second), however, the insert and update will be much less often. Why would it matter if such a small amount is being held in memory?  Thanks

If you're using it often then the "isn't being used" bit is not true.

 

Like tables at a restaurant, it's just not a Nice Thing To Do to reserve resources if you're not going to use them. Even if it's one small table at a large restaurant.

  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.