Comments (8)
P.S: The unmodified version of 001_connect
runs pretty nice in PHP7.
If it's expected to run in 7, just close this one, I'm fine :) Great job btw.
$ php -v
PHP 7.0.0-dev (cli) (built: Feb 15 2015 23:06:04)
from mysql.
@douggr I believe the reason you're getting this result is ...
When you create a new Pool
instance it schedules the connection to be setup in the next tick of the event loop. When you use yield
on the new pool instance the generator passed to Amp\run()
won't resume at that location until the next tick so it "just works." Without that artificial pause the connection isn't allowed to initialize internally before the subsequent offending call.
@bwoebi you generally want to return a promise from $pool->setCharset()
for this reason. Anything someone can possibly wait on with yield
should return a Promise
.
In the case of the Mysql\Pool
where you have multiple connections this is probably as simple as:
$promises = [];
foreach ($this->connections as $conn) {
if ($conn->alive()) {
$promises[] = $conn->setCharset($charset, $collate);
}
}
return all($promises);
from mysql.
@rdlowrey I don't think you should wait on setCharset(). It basically is just setting a connection property. It has no return value and it always should be transparently resolved...
@douggr thanks for the report, I'll look at it this evening.
from mysql.
I don't think you should wait on setCharset()
That's fine if you want to do it transparently and not return a promise, but if so you just need to track the internal connection state yourself so the operation doesn't error out if it's invoked before the connection is established.
@douggr Just as an FYI ... in the future yielding something like the mysql pool instance will result in an error as it's not actually a "yieldable" thing (Promise
, Generator
, null
). So it's really only a temporary fix. Note that if you want a future-proof way to work around this problem you can always use the "pause"
yield command key inside any generator function to yield control for the specified number of milliseconds like so:
run(function() {
echo "tick\n";
yield "pause" => 1000;
echo "tick\n";
yield "pause" => 1000;
echo "tick\n";
});
from mysql.
@rdlowrey Yes, I'll look into it now...
But a setCharset() is just a configuration thing and shouldn't throw any exceptions nor return any success value. So promise is not needed.
from mysql.
Thanks for the feedback guys.
@rdlowrey Yes, I understand the amp
workflow, have been using it a
while ago. I'm about to open-source a project using amphp goodies :)
But's offtopic for now.
@bwoebi Although I still have no idea where's the problem is, I realized
that it's not related setCharset()
but to the Pool
and/or Connection
.
You can't just connect and then close the connection if no one query is
executed because the event loop was not started. Thats said, so in a
case an app connect to the database and executes without querying the
db it'll run into this issue.
A workaround I'm using for now is query('select 1')
just to get it up and
running. It's ugly :)
from mysql.
I found the issue, which is basically a missing check. Will fix shortly, but I've found another issue while working on this :-) (indefinite loop)
from mysql.
Fixed via efddc15 // That other issue in reality was an uv-related issue which was already fixed in amphp/amp but not yet tagged (sigh).
from mysql.
Related Issues (20)
- Implement Support for Protocol::AuthSwitchRequest
- Can we use Named parameters in SQL queries with amphp\mysql package? HOT 1
- Can we have lastInsertId returned in a different method when UUID is used as Primary Key? HOT 4
- Connection closed unexpectedly HOT 4
- Values not saved when named parameters are used in SQL insert queries with amphp\mysql package HOT 3
- about wrapping CommandResult HOT 1
- multi query with prepared statement HOT 5
- Different query result under transaction
- v3 not work HOT 3
- Connection open + one select + close takes about 30 ms HOT 5
- Prepared Statements don't work with DATETIME columns HOT 2
- Reaching connection limit results in protocol version exception HOT 1
- Incorrect handling of fractional seconds in Datetime, and Timestamp columns HOT 3
- Connection closed unexpectedly HOT 2
- Cannot install HOT 5
- Unable to connect to AWS Aurora MySQL 3.04.0 (MySQL 8.0.28) over TLS HOT 5
- Connection closed unexpectedly HOT 4
- Closing database connection while query is still pending HOT 2
- Infinite recursion when iterating HOT 5
- v2: is it possible to set a limit on the max number of parallel connections? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mysql.