NotionCommotion Posted December 11, 2017 Share Posted December 11, 2017 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... Quote Link to comment Share on other sites More sharing options...
requinix Posted December 12, 2017 Share Posted December 12, 2017 Theoretically it would be good forever (or until something restarts) but I wouldn't do it for the simple fact that you'd be holding onto memory that isn't being used. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted December 12, 2017 Author Share Posted December 12, 2017 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted December 12, 2017 Share Posted December 12, 2017 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. 1 Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted December 12, 2017 Author Share Posted December 12, 2017 Nice analogy! But begs the question, "what is often?" Quote Link to comment Share on other sites More sharing options...
requinix Posted December 12, 2017 Share Posted December 12, 2017 Arbitrary. 1 Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted December 12, 2017 Author Share Posted December 12, 2017 Arbitrary. Thought so Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.