Chapters
48 Chapters
|
5:05:05
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Este tutorial está construido con Symfony 4.3, pero funcionará bien en Symfony 4.4 o 5.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // v1.8.0
"doctrine/doctrine-bundle": "^1.6.10", // 1.11.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.6.3
"intervention/image": "^2.4", // 2.4.2
"league/flysystem-bundle": "^1.0", // 1.1.0
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.1
"sensio/framework-extra-bundle": "^5.3", // v5.3.1
"symfony/console": "4.3.*", // v4.3.2
"symfony/dotenv": "4.3.*", // v4.3.2
"symfony/flex": "^1.9", // v1.21.6
"symfony/framework-bundle": "4.3.*", // v4.3.2
"symfony/messenger": "4.3.*", // v4.3.4
"symfony/property-access": "4.3.*", // v4.3.2
"symfony/property-info": "4.3.*", // v4.3.2
"symfony/serializer": "4.3.*", // v4.3.2
"symfony/validator": "4.3.*", // v4.3.2
"symfony/webpack-encore-bundle": "^1.5", // v1.6.2
"symfony/yaml": "4.3.*" // v4.3.2
},
"require-dev": {
"easycorp/easy-log-handler": "^1.0.7", // v1.0.7
"symfony/debug-bundle": "4.3.*", // v4.3.2
"symfony/maker-bundle": "^1.0", // v1.12.0
"symfony/monolog-bundle": "^3.0", // v3.4.0
"symfony/stopwatch": "4.3.*", // v4.3.2
"symfony/twig-bundle": "4.3.*", // v4.3.2
"symfony/var-dumper": "4.3.*", // v4.3.2
"symfony/web-profiler-bundle": "4.3.*" // v4.3.2
}
}
6 Comments
Hi. Just watched this tutorial and an idea popped into my head. What if we dispatched query message from controller through a transport (to handle it asynchronously), then executed some logic in controller and then wait for a message to be handled? That way we could run some code in parallel to query handling. For example:
Would this work?
Hey Adeoweb!
Hmm, interesting. On a high level, I think it *would* work... but you'd have a few challenges and problems. The biggest one is if your workers are busy... like maybe it takes 30 seconds to find the time to handle your message. That's... not too much fun. Even a quick response could take 1/2 a second, which in "web request" time is really long. So... it's tricky to get this to happen in practice, in large part because the philosophy of works is that the work is done "as quickly as possible"... but some delays are no huge problem, since nobody is waiting for the info.
You would also need to implement some extra logic in Messenger to make it work, but due to the above problems, you won't see that functionality. I'm sure *someone* has done this *somewhere* and gotten decent results, I just don't know an example. Maybe a microservice architecture might be the best example. Imagine you dispatch a message *synchronously*, but the handler actually sends an API request to some other service which (again, synchronously) does some work and sense back the answer. Then, once all of that finishes, in your controller, you can read the result. The end result is actually quite close to what you're proposing. You send the message async, but doe to the "sleep", in reality, everything happens sync anyways.
Let me know if that made any sense ;)
Cheers!
Well, my idea was running multiple tasks in parallel at the same time and then synchronizing the main thread with all those threads. For example in javascript you can create one (or more) promises so they all could be handled in the background at the same time, in parallel. Then, while all the promises are being handled, the main thread could do some other work (at the same time, in parallel to promises) and then you can wait for all the promises to finish. You can do similar things in C# using tasks - you can create multiple tasks, so they can run in parallel at the same time, and when you need to synchronize your main thread with these tasks, you can await them. So microservice approach is not really fitting here.
I've got your point in the first paragraph. To solve the problem, one could implement some extra logic that would spawn PHP message handler process for every message dispatched. That way we would have a true multithreading system in PHP just like in C#. Maybe I will test my idea when I will have more free time. I will post the results here in a reply.
Thank you!
Hey Adeoweb!
Ah, I understand better now! There is a new feature (that I have not looked into yet) in PHP 8.1 called Fibers - https://betterprogramming.p... - that might (or might not) be somewhat related to what you're saying :).
Anyways, let me know if you do some experimenting!
Cheers!
HI.
Any reason why this video has not been released yet
Hey!
Good question. The thing here is that this is not the last video of the course. Ryan is preparing more content but at the same time we are actively releasing the "ApiPlatform Security" tutorial. We just need some more time :)
Cheers!
"Houston: no signs of life"
Start the conversation!