PHP Fibers & Asynchronous Under 11 Minutes

Поделиться
HTML-код
  • Опубликовано: 11 июл 2024
  • This is an introduction and a quick start with Fibers. This new feature in PHP 8.1 enables lightweight and controlled concurrency in PHP. By implementing Fibers, developers can create high-performance applications. Watch this tutorial to gain an in-depth understanding and learn how to implement Fibers to optimize your PHP code.
    📺 Recommended
    --------------------------------------------------
    Top 5 Design Patterns in Software Engineering: • 5 Necessary Design Pat...
    PHP 8.2 is good! What's Changed & Improved: • PHP 8.2: Is This the U...
    PHP Generators & Iterators: • PHP Tutorial: Generato...
    🧾 Timestamps
    --------------------------------------------------
    0:00 Intro - Fibers in PHP
    0:36 What are Fibers?
    1:16 What are Synchronous & Asynchronous Calls?
    1:54 Fibers vs Asynchronous
    2:41 Thread Class in PHP
    2:54 Fibers vs Thread
    3:47 Fiber Example with PHP | Coding
    9:09 Some More Tips for Fibers in PHP
    9:49 Outro - Fibers in PHP
    #php #fibers #async #sync #api #programming #synchronicity #asynchronously #learnphp #development #backend #softwareengineer #tutorial #programmingtutorial #phptutorial #DeskNook

Комментарии • 29

  • @DeskNook
    @DeskNook  2 года назад +1

    Subscribe
    Subscribe
    Subscribe
    ...

    • @daviddavid-zl6gw
      @daviddavid-zl6gw Год назад

      Hello why fiber is not activated for php-v8.1 in debian 11, how activate fibers the extension isn't loaded, thank u

    • @DeskNook
      @DeskNook  Год назад

      @@daviddavid-zl6gw I'm using ubuntu 22 which is a debian based distribution with the latest update of php8.1 & php8.2. Fibers work fine with both, so for your issue, I suggest to try with a clean install of php

    • @daviddavid-zl6gw
      @daviddavid-zl6gw Год назад

      @@DeskNook
      Thanks for your reply,
      it's good, "fiber" it works very well, the problem is in my code I used an old script which uses fiber->create instead of fiber->strat()
      I want to ask you a question that can help me, which use is the most efficient in parallel execution time: to use fiber or pcntl_fork.
      Thank you.

    • @DeskNook
      @DeskNook  Год назад

      @@daviddavid-zl6gw pcntl_fork is more efficient than Fiber, however I prefer to use fibers or pthreads

  • @johnsteve1276
    @johnsteve1276 5 месяцев назад

    thank you so much, brother!

  • @ZAcharyIndy
    @ZAcharyIndy 2 года назад

    Thanks

  • @kadbano.m8420
    @kadbano.m8420 2 года назад

    It was great I used

  • @GonzaloMassa
    @GonzaloMassa Год назад +2

    You don't need a for loop if you want to keep track of the index, you can just do foreach($files as $index => $file)

  • @indrasaputra87
    @indrasaputra87 4 месяца назад

    For those who ask, what is the use of the multi-thread capability? This feature will be useful for those working on very large data or processes, such as 10 million pieces of data that need to be processed individually. for PHP is a single thread it will definitely take a very long time to process one by one, with multi threads the work will be completed much more quickly (by using CPU and RAM resources more optimally).
    but I'm tired of researching PHP, it seems PHP is not designed for true multi-threading. I've moved to C#, a real multithreading language and don't want to go back 😅
    thank you for the video , mate!

  • @sliceem88
    @sliceem88 2 года назад +1

    Hey ! nice vid.
    Maybe you could use some kind library swool or ReactPhp or Amphp. Show differences and usage?

    • @DeskNook
      @DeskNook  2 года назад +1

      Thanks buddy. For Amp/ReachPHP the difference is in the scope, both are written by PHP and already updated with Fibers. Swoole is an extension, good in performance and features.

    • @sliceem88
      @sliceem88 2 года назад

      @@DeskNook yes, i've seen comparison between nodeJs and swool.
      In ReactPHP there were yeald hell some time ago, but in AmPhp there where sort of promises already.
      Who is faster and yeasy to implement, in your opinione?

    • @DeskNook
      @DeskNook  2 года назад +1

      I remember an old benchmark that ReactPHP got a higher speed factor than Amp, for now there shouldn't be much difference between these two.
      I prefer React, Amp more readable with Auryn & Coroutines.
      I would choose one if it wasn't a cool thing for me and go with another one, this is my strategy :)
      Have it in mind, you can use Amp as an event loop for React (means you can use both)

  • @daviddavid-zl6gw
    @daviddavid-zl6gw Год назад

    I apologize for the inconvenience,
    I have another question, you did not test the execution time by a normal loop script and by Fiber, to notice that it is faster than normal

    • @DeskNook
      @DeskNook  Год назад

      Its not faster than normal, thats not the point about Fibers. Check out 0:35

    • @daviddavid-zl6gw
      @daviddavid-zl6gw Год назад

      @@DeskNook I didn't really understand what is the purpose of using Fiber, I tested your code in both cases the case with normal loop and the case with Fiber, the execution time is the same 0.003s.
      Please can you explain to me even in a line what is the best to use fiber (Do you mean that it is available for making a multitasking framework)
      do you know a multitasking framework that uses fiber, instead of using pcntl fork, I want to execute the same code in parallel on several hundreds of data, each processing takes 3s to finish, I want everything to finish in 3 sec, not in 3s X 100 ?
      Thank u.

    • @DeskNook
      @DeskNook  Год назад

      ​@@daviddavid-zl6gw As a short answer to your questions, Fibers are good for non-blocking stuff.
      I highly recommend you watch the video again.
      That example in the video is just about how to use Fibers, neither async nor performance.
      In case, you may use pthreads via cli mode too.

  • @snithfferx
    @snithfferx 8 месяцев назад

    Un poco de volumen no vendría nada mal.

  • @mobinamahmudian2243
    @mobinamahmudian2243 Год назад

    seda ghashng😂

  • @issamjaafari5519
    @issamjaafari5519 Год назад +1

    Great video, but I didnot get the idea of this function

    • @DeskNook
      @DeskNook  Год назад +1

      The Fiber is an easy way to have async in PHP

    • @issamjaafari5519
      @issamjaafari5519 Год назад

      @@DeskNook keep it up, great way to explain, need more videos for php 8.2

    • @DeskNook
      @DeskNook  Год назад

      @@issamjaafari5519 Thanks, sure

  • @nathanielsabanski
    @nathanielsabanski Год назад

    file_put_contents() is blocking, this won't work unfortunately.

    • @DeskNook
      @DeskNook  Год назад +1

      Thats blocking so our files are created in order from a to z, actually the code works fine with file_put_content however it's not optimized for async

  • @kubaleman3440
    @kubaleman3440 Год назад +1

    still dont understand what thsi featreu can give me in any project

    • @DeskNook
      @DeskNook  Год назад

      There is not use for fibers in usual projects, its for low level programming better for async purpose

    • @smtkumar007
      @smtkumar007 3 месяца назад

      i used to work in both node and php , for web development there is hardly any need of aysnc code , cause i found myself using aysnc await always for thing to work on node as its async by default , while php is sync by nature which is mostly u will be needing if working on web devlopment. But if there are some tasks where IO operation needs to be performed then i can see this beign usefull , as now i use to call python or c# to process the data , now i guess that will change. Hard to digest that it took them decades to put this in php ecosystem.