Adding a close method or alternatives for persistent objects (i.e. PDO)
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
PHP has been moving towards using objects instead of resources. One change as a result of this is that the resource the object represents gets closed on the destructor, instead of calling extension_providing_resource_close methods. Normally, this is OK, as you can just remove all references to an object and have it clean up. However, with persistent resources, the extension holds a reference onto the object that it provides to you, preventing you from being able to destroy the object. This use case might exist for i.e. cleaning up a persistent database connection that has gotten itself into a wedged state that the extension can't handle (i.e. ODBC liveness checks aren't perfect), or closing something to finalize something done over multiple requests.
The easiest option may be to add a close method to the object, similar to what i.e. SQLite3 does. Some extensions like curl already have close methods, but they might have been converted to nops in the resource to object conversion. However, this adds issues with having an object that represents i.e. a connection in a closed state. (However, since one of the cases is say, closing a database connection, we already might have to deal with live objects that represent a resource that's been closed.)
Another option might be to expose a list of currently used persistent resources. get_resources can be abused for this, but contains massive footguns and only works with legacy resources. Perhaps this can be done for persistent objects in general in a safer manner, or have a persistent object list provided by the extension. Persistent object issues can be hard to debug, so this might be generally useful.
See: https://github.com/php/php-src/pull/15603#issuecomment-2329536824 - there might be other conversations on this
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the issue's discussion of PDO persistent resources, SQLite3 and curl close methods, and the linked pull-request conversation. Compare the proposed close-method and persistent-object-list alternatives; done requires an agreed API and implementation approach for safely handling persistent objects and closed resources.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php, sqlite
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100