what happens if you have an exception in the defer callback? in queues at least you could re run failed jobs. what happens when you go pass 30 seconds limit for example in cloudflare?
Thank you for that, i just wonder how to make testing for this, i am using Pest and i am facing an error some thing like this PHP Fatal error: Uncaught Swoole\Error: API must be called in the coroutine in.... any idea?
It would be awesome when explaining when to use defer or jobs is to give examples like hey use defer for these scenarios that you would use in web development and use jobs for these examples could be short and simple explanation
let's say you have a list of items, paginated. and on render, you have to process/calculate something. if this is time consuming, you can defer a pre-calculation for all entries in the next/previous pages of the current page the user is viewing (and save them in cache). this way, when user clicks prev/next button, the page will load instantly (and the next/prev one starts processing in background and so on).
the user's request results is already sent and the process is now running standalone, it has no clue what the user is doing on their end, so it keeps running no matter what the user does - unless you intentionally somehow "watch" for new incoming requests in the closure code your pass to the defer() function.
I suppose there is no guarantee this defer code will keep working for a long time in cloud setups, like Vapor? Lambda executor could be terminated and your defer code could end up with partial result, resulting in corrupted data.
the "guarantee" is the same as if the code were executed without the defer. so if your time executing limitations is 30s and the task could not be completed as a regular code (before sending response to user) it won't execute as deferred code as well. this function is to be used to speed up navigation (do not make user wait for the small tasks to be completed before rendering page if these tasks will take just a few ms/secs and the probability of the successful completion is [near] 100%)
I just learned 70 things in 14 minutes. Sweet new promo for laracasts at the end there. I'll be deferring tons. Thank you, Jeffrey and Laravel
Laravel is now my favourite framework.... 🔥
i’m working on a project, right now, this is magic !!
Very good!!! I will use it in my applications. Thank you!
The outro is 🔥🔥
I Learn new stuff today, thanks laracasts
Very nice outro ❤🔥❤🔥❤🔥
Wow! This is cool!
Jeff I will meet you once in life from India
wonder what issues timeouts causes with this defer 🤔
So much knowledge to bite, delicious. but Where is the PHPStorm like usual
Nice lets try it out
Hi. In my Laravel app v-11.23.5 the defer is not working. My app migrated from version 10.23 to version 11 2 months ago.
what happens if you have an exception in the defer callback? in queues at least you could re run failed jobs. what happens when you go pass 30 seconds limit for example in cloudflare?
One of my biggest fears with running things after response is not being able to track failures.
Thank you for that, i just wonder how to make testing for this, i am using Pest and i am facing an error some thing like this
PHP Fatal error: Uncaught Swoole\Error: API must be called in the coroutine in....
any idea?
is defer a good use case for when deleting a row can cascade into deleting multiple rows like up to 10000 or a queue and job would be better for this?
If your project depends on it use the queue, otherwise use the defer.
When something could go wrong and you need to retry, use always the queue.
What about the status code define inside defer function? Will it execute the last response?
Just wonder. How it will works with try catch, cashier and stripe ?
Respect from Pakistan
It would be awesome when explaining when to use defer or jobs is to give examples like hey use defer for these scenarios that you would use in web development and use jobs for these examples could be short and simple explanation
let's say you have a list of items, paginated. and on render, you have to process/calculate something. if this is time consuming, you can defer a pre-calculation for all entries in the next/previous pages of the current page the user is viewing (and save them in cache). this way, when user clicks prev/next button, the page will load instantly (and the next/prev one starts processing in background and so on).
How the database transaction behave?
What will happen when the user navigates to another page will defer function still executed?
the user's request results is already sent and the process is now running standalone, it has no clue what the user is doing on their end, so it keeps running no matter what the user does - unless you intentionally somehow "watch" for new incoming requests in the closure code your pass to the defer() function.
I suppose there is no guarantee this defer code will keep working for a long time in cloud setups, like Vapor? Lambda executor could be terminated and your defer code could end up with partial result, resulting in corrupted data.
the "guarantee" is the same as if the code were executed without the defer. so if your time executing limitations is 30s and the task could not be completed as a regular code (before sending response to user) it won't execute as deferred code as well. this function is to be used to speed up navigation (do not make user wait for the small tasks to be completed before rendering page if these tasks will take just a few ms/secs and the probability of the successful completion is [near] 100%)
The first thing come to my mind is mail
But it's nice to have mail queued so that if there is a temporary problem with the mail server, you can rerun the queues.
Hold on a second, this looks like VS Code... 🤔🤔🤔🤔🤔
I believe it is.
Using Cursor? 👀
Lol jeffery is dictionary like so much info in 13:59 amazing hope you give us an advanced laravel project like 30 day series
Wait a minute, what's that dump extension @ 1:07 ?
Laravel Herd