 Hai. Selamat pagi. Pada masa ini, saya akan bercakap tentang PAHP Reaktif Programming atau Reaktif Programming di BHP. Dan apa sebenarnya Reaktif Programming dan bagaimana kita dapat menggunakan itu di BHP. Saya juga akan bercakap tentang beberapa perempuan programming kerana ini juga berkaitan dengan reaktif programming. Okey. Nama saya Doli Aswin. Saya dari Indonesia. Saya mulai programming di BHP sejak 2004. Dan ZEN35, penyelamat BHP5 di 2010. Dan ZEN35, penyelamat ZEN11. Dan di 2015, saya dapat ZEN2, penyelamat ZEN3. Okey, terima kasih. Apa adalah reaktif programming? Reaktif programming telah menjadi sangat popular dalam beberapa tahun yang terakhir. Dan walaupun ide-idea di belakang ini adalah baru-baru. Ia mengambil sesuatu yang baik daripada beberapa perempuan programming yang berbeza. Okey, ini perempuan reaktif programming. Kamu boleh periksa dan kita beritahu. Perempuan reaktif programming adalah perempuan programming yang berkaitan dengan data stream dan perempuan perubahan. Ini bermaksud ia menjadi kemungkinan untuk menjelaskan statistik atau data dinamik, atau data dinamik yang berkaitan dengan perempuan perempuan programming. Okey, apa yang sebenarnya perempuan programming? Ini perempuan programming. Ini adalah sebuah konsep yang mempunyai percayaan dan pembinaan. Pada perempuan programming, seperti PHB, mengucapkan perempuan berkaitan. Kita boleh juga berfikir, ini adalah sebuah perempuan yang berkaitan. Kita mengucapkan masalah apabila kita menggunakan perempuan perempuan. Kerana reaktif programming menggunakan beberapa perempuan programming, kita akan menggunakan perempuan perempuan perempuan reaktif programming. Mungkin kita selalu dengar, apabila anda dengar tentang perempuan reaktif programming. Ini adalah perempuan perempuan programming yang digunakan dalam perempuan reaktif programming. Ini adalah pengaruh kecumaan, sekatang-catang dan fungsi. Okey, kita bercakap tentang perempuan perempuan perempuan. Apa kesempuan kecumaan kecumaan kecumaan? Deklari program ini adalah pemerintah yang fokus pada menjelaskan program logik tanpa kecuali perkembangan. Di gambar ini, jika anda bercakap dengan kawan anda dan kawan anda, jika anda tidak memperkenalkan kawan anda dengan perkembangan, bagaimana untuk membuat perkembangan. Jika anda melakukannya, ia akan rasa seperti programkan kawan anda. Jika kawan anda dapat mengikuti perkembangan anda, ia akan menghubungi perkembangan ini, membuat saya melakukannya ke dalam perkembangan serius, seperti yang pertama, menemukan perkembangan, yang kedua, menghubungi perkembangan, dan ketiga, menggunakan perkembangan. Deklari programnya, kita memutuskan apa yang kita mahu, tanpa bagaimana kita mahu. Dan perlahuan yang lain sekarang akan dikatakan, dalam satu kecuali kita mempunyai untuk membaik perkembangan, tapi perkembangan yang ditatuk dengan Letak untuk kami. Dan kita tidak perlu risau sebab berapa bahan bilangan menggunakan perkembangan untuk data. Kita lanjutkan dengan Raising Chronos. Ini adalah exemplan Raising Chronos. Ezyngronus adalah minumum idle tijd, mengubah tanda. Seperti di image ini, ini adalah proses untuk mengambil pengguna baru. Mungkin ini proses yang penting. Pertama, kita mengambil pengguna baru, kemudian kita mengambil e-mail yang terbaik, kemudian kita beri kelebihan ke klien. Dengan Ezyngronus, flow seperti ini kita mengambil pengguna baru, kemudian untuk mengambil e-mail, kita mengubah tanda. Dan kita tidak menunggu pengguna baru, kita hanya beri jawatan. Ini adalah proses yang sama, tetapi ini menggunakan pengguna baru. Kita mengambil pengguna baru, mengambil pengguna baru, kita mengambil pengguna baru, kemudian kita beri jawatan. Dan masalahnya, bagaimana jika koneksi internet menjadi rendah? Mereka akan mengambil pengguna, kerana ia perlu menunggu e-mail, kemudian beri jawatan. Dan kemudian ia akan mengambil banyak masa, dan mungkin membuat pengguna baru. Dan ia akan lebih baik untuk memulai proses pertama dan bukan menunggu proses ini untuk dibuat. Kita membuat proses lain, kemudian kemudian kita kembali ke proses dan membuat pengguna dari mana kita memlepaskannya. Ini adalah idea utama menggunakan pengguna baru. Pengguna baru tidak sama dengan parallel. Paralelisme adalah pengguna baru dari beberapa perkara. Mereka mungkin berhubung pada mungkin atau tidak. Dalam pengguna baru, kita berkongsi dengan banyak perkara dan banyak perkara yang berbeza. Biasanya, ketika mereka melihat pengguna baru, mereka akan mengikuti perkara parallel. Peralelisme tidak sama dengan pengguna baru. Peralelisme tidak berlaku banyak perkara, tapi perkara ini adalah idea yang berbeza. Peralelisme adalah tentang struktur dan peralelisme adalah tentang pengguna baru. Apabila mengelakkan sesuatu, maksudnya, pengguna baru tidak terlalu berusaha. Apabila mengelakkan sesuatu, maksudnya, berkata, berkata, berkata, berkata, berkata. Ini adalah pengguna baru. Peralelisme tidak sama dengan pengguna baru. Apabila mengelakkan sesuatu, maksudnya, berkata, berkata, berkata, berkata, berkata, berkata, berkata, berkata, berkata, berkata, berkata, berkata Orang yang lebih tinggi mempunyai maklumat yang sangat sama dan mempunyai sekurang-kurangnya satu dari ini. Pertama, mengambil fungsi sebagai peningkatan dan kedua, menerima fungsi sebagai kata-kata. Dalam program fungsi fungsi yang lebih tinggi mempunyai Mereka menggunakan kata-kata menggunakan sukses, map, filter, reduce, concat, dan zip. Okey, saya telah memberitahkan sedikit tentang program-program dan sekarang kita kembali ke program rektif. Ini adalah diagram marble untuk mengenali stream rektif. Seperti yang kita lihat di timelan pertama, ia adalah data stream. Di timelan kedua, ia juga data stream. Dan ada operator merge. Kemudian data stream menjadi timelan. Kemudian ada operator filter, data filter. So data with failures less than 4 will be filter. And the result is in this timelan is just 3 and 1. And there is a map operator so the data will be 4 and 2. Rektif programming is yet another programming paradigm. It is based on the ability to easily express data flow and find automatic propagation. Propagation of change. This reactive concern with this following. Data flows, propagation of change, and easily express data flow. And what is the data flow? The data flow in reactive programming we want to think about variable as failures that change over time. For example, this could be a most position, user click, or data coming via web socket. Basically any even best system can be considered also as a data stream. And what is the propagation of change? Propagation of change, a very nice example for this is a spreadsheet editor. We can see this single cell to C1 is A1 plus B1. If we change to cell A1 and B1 will be propagated to the C1. In programmer mindset, this is related to observer design pattern. Where A1 and B1 are observable and C1 is unobservable. And we continue to express easily express data flow. The first part of about data flow and propagation of change may be similar with observer design pattern with iterables. And for this we can do it easily by functional programming. And this is a simple explanation about what is the observer design pattern. The observer design pattern, also known as public subscribe pattern, is a behavioral design pattern which defines one-to-many relationship between objects such that when one object change is that all dependent objects are notified and updated automatically. This principle is very similar also with Zen event manager in Zen framework. I don't know in other framework, maybe Sympony also have even manager like this. Or Laravel maybe. Now we have see that principle under reactive programming paradigm which is not completely new for us. And we can start thinking about how to put it all together. In other words, what list query or framework do we really need in order to start writing reactive code in PHP? Okay, there is a reactive X or just RX. This is set libraries in various language that make reactive programming easy. Even in language where concept and synchronous and functional programming Reactive extension is ready to introduce certain principle and one of the possible way to approach reactive programming. Reactive extension were originally made by Microsoft for .NET and called RX.NET. Later, it was ported by Netflix to Java as RXJava. And now there are over a dozen supported language. The most probable being RXJS for the Javascript implementation. This is the very basic example of RXPHP usage. Can you see the code? This is the very basic. The purpose for this script is to print string length of the fruits on the variable fruits. In this example, we have an array to be streamed by observable. That is the fruits variable. And two operators, the operators are map and filter and one observable. These observable can be chain with operators, map and filter. And observable have the subscribe method. This is used by observer to receive failures at the end of the change. We use the observer as callback observer which has three function as arguments. The first is called when the next item is ready to immediate. And the second is called when the error has occurred. This could be any type or error represented by an instance of the exception class. And the third is called when there are no more items to be immediate. And this is the output of script. The first, next, change charge. This is come from the watermelon. And the second charge is come from the strawberry. And the next eight charge is come from the pineapple. The grape is not counted because there is a filter for the string length. If the length of string, it just process the string with length greater than 5. And this is the complete. It means the process has been complete. As we see, these observable like iterating an array but actually they are different. This is the difference between observable and iterating an array. Observable are like a push model where a value is pushed down to the operator chain when it's ready. This is very important because it's the observable that decides when it should be immediate to the next value. The internal logic observable can do whatever it needs and still remain completely hidden. And iterating the array is like a pull model. We be pulling one item after another. This is my world diagram also for observable. Observable behave like a data stream. Observable knows when it has immediate each item or when an error has occurred and able to send proper notification proper notification down the chain. This is the chain for representing the... This is the diagram for representing the chain where this is observable then there is my operator and filter operator and this is the lattice is observable. It shows the direction of propagation of items and notification. This is the observable. It will call 3 methods from its observable that is on next. This will call when the next item is ready to immediate. This is on error. The notification call when an error has occurred and this is uncomplete. It's called when there are no more items to be immediate. Observable can call 3 different methods on their observers. Each observable can emit zero or more items. Each observable can send one error or one complete notification but never bought. In RXPHP, every operator takes a callable as an argument wraps it call internally if the callable drops exception. Then this exception is sent as on error notification. This is the example. This is the observable. We get the observable from array and we do checking here. If we found a berry on the string we throw the exception. This exception is fruits with berry rejected so this is what we'll call the on error. Okey, let's check the result. This is the result. It just print the length of the first the first of fruit and because the second of fruit is strawberry so it throw an error. So the error will handle by the on error method. When an error occur no more items were immediate. So when there is an error throw so the emitter will not chain again. There is also no complete notification and there is no complete. This is because when observer is an error it automatically unsubscribe. Okey, I will talk about the RXPHP basic principle. This is the components of RXPHP. These are components. There is observables and observers. I have give a little explain about it. There is also singles, subject is possible, secure ruler and operators. This is the addition for the observable. Observable emit an item. Observer subscribe to observable and observable notify data is immediate and error is occur. In other words observable are source of values. Observer can subscribe to observable in order to be notified when the next item is ready. Our items have been immediate or an error has occur. The main difference between unobservable in this reactive programming and the observer reason better is unobservable can tell you when all data has been immediate and when an error occurs. All three types of events are consumed by observer. In RXPHP there are three types of observable. So the observable can be created by this. There is an array observable, range observable, iterator observable. The array observable is create an observable from an array and emit all values right after the first observer subscribe. The range observable this generate a sequence of number from a pre-defend range. And the iterator observable this is iterate and emit each item in iterable. This can be any array write as iterator. So this is how to create the observable. All built-in observable in RSPHP can be instantiate easily by calling static method from the RXR observable in space. The following list represent the three observable mentioned before. Also it usually easier to use static calls than to instantiate observable directly. Okay we continue to observable. Observable are consumer of observable. The constructor takes three optional arguments representing callables for each type of signal. The first on next like before, on error and on complete. In other words observable react to on observable react to observable. We have already seen the callback of observer class. We take three optional arguments representing callables for each type of signal. This is the sample of observable. We create our own observable class for useable to test what is going on on inside of observable chains. We implement three method that is complete and next and error Okay. This is a singles. Singles are like observables but the only difference is that they always emit just one value. In our space HP we don't distinguish any difference between observable and singles. So we can use the observable just method for this. Okay on this example we create on observable with just one value that is 100 and we set the subscriber or observer is print value that we create before here. This is the observable and we use this on this. We set the observable as 100 and this is the output. We just emit one value. This is the scope. The observable have 100 for value and this is just one value. Then we use the observer we create before here and the result is here. Just one value emit to observer. Okay there is also subject as component of RxPHP the subject is class that acts on observable and observer at the same time. This means it can subscribe to an observable just like an observer and also emit values like observable does. Eventually it can also emit its own values independently of its source observable in order to see the subject class can be used in different situation. I will give example based on the same example we use at the beginning of the slide. This is how the subject works. I use the subject as observable I create the, I instance the object and add operator map and filter and also the subscribe method and use the print value of observer we create before. So to emit the values I just call the un-next I call for un-next method the first grape, watermelon, strawberry and pineapple. So the output is next 10 charge. This is come from watermelon and next 10 charge. This come from strawberry and next 8 charge come from pineapple because we have a filter in this. We just process that data for the length is greater than 5. Okay, this is the subject as observable. This is subject as observer. I create the subject then add a filter and add subscribe with the observer and this is the fruits array then I create the observable based on the array and add map operator and add subscribe to the subject object from the above. So this is the subject act as an observer. Bevor the subject is act observable and this example he also can be used as an observer. And there is also the example this is subject in the middle of operator of change. This is the array for the fruits I create the subject then I add filter to the subject and I add subscribe to the print value the observer and create the observer from the variable and add map function and add subscribe subscribe to the subject this is the example for subject we can use subject in the middle of operator of change and as we can see the result the output also same with the previous example the output also same ok, we continue to disposable or RX implementation internally use the disposable pattern you can read about more disposable pattern in Wikipedia this design decision has two reasons the first to be able to unsubscribe from an observable and second to be able to release all data used by the observable and in RXPHP there also scheduler observable and operators usually done execute their work directly but use an instant of the scheduler to decide how when it should be execute in most situation in RXPHP we don't have to even worry about the scheduler because if we not manually our observable and operators internally use the immediate scheduler class which execute our action immediately without any further logic so this scheduler can be also combined with even loop from RXPHP this is the example applying an even loop from RXPHP for observable this is the way how to do it so no problem if we don't prepare the scheduler we can use even loop or use the default scheduler from the RXPHP okay and we continue to operator in RXPHP operator and in RX operator is to use to modify data flow and it also can return another observable and allow chaining of operator calls and in RXPHP there are about 40 operators and we have used some operators before we have used filter map and I will give some explanation but not much for how operators together but we don't much time for explaining this all operators maybe just take some operators we use before okay, we start from filter the behavior of filter operator is the same it just work with data flow instead of arrays this means it receive item from its source and propagates to its consequence observer or chain operator this is the marble diagram can you see so in the first line and the first row this is the data stream there is a 5, 10, 12, 20 and 18 then this is the filter the filter is filtering the data stream and the result will be 10, 12 20 and 18 this was pretty simple but this marble diagram may be comparable way of representing data flows without worrying about implementation detail okay, there is also concate operator this operator is similar with merge merge is this merge operator used for this diagram so this concate is similar with merge the operator merge multiple observer into one observable it internally subscribe to each observable in order one after another this is the diagram as we can see the first row 10, 12 20 18 and in this second row that is 20 and 14 so the concate operator merge all into one data stream so you can see they are now in one data stream this is maybe an explanation or theory about the ISPHP maybe I will give simple demonstration how to add a simple logic to observable and observer using RSPHP okay you can see the code see we just use a theme this is better one size can you hand this is better this is a simple script for retrieving data from GCN Placeholder Album GCN Placeholder Album is fake GCN maybe you know about the site this is the data so in this example I from this GCN this is the data and this is the script okay the first I call the class there is a I create a GCN Placeholder Album is observable then I create the operator and I create the observer and also for HTTP claim I use gazelle this is the I create the observable so because this not limited I think this is contain about 100 data so for by using this Rx we can set the limit using the take method we just limit to 10 and I use the custom operator I create before to read the GCN and then this is a custom observer okay I will open the this is the first we open the observable this is the observable I extend from array observable this is the default you are on okay this is the this is how to make HTTP request and the result is make as observable by is array observable construct this is the observable and this is the operator in this operator I just filter I just take the title from the GCN this I just take this text and emit the failures to observer and if the result there is no ID it will throw an error I will open the observable okay this is the observable print failure okay and this is we back to the script for that which implemented the all operator observer and the observable this is the script I run it I run it using docker oh this take the 10 of data from the GCN if I increase the take 20 in the data okay this is a short example for how to add the logic to observable and how to create the observer and operator back to the okay the summary reverse using reactive programming make our code concase clear and readable maybe we can make the simple case using iterating an array but if you extend add more logic maybe it will be too complicated by using the reactive you can extend it and the code is more readable reactive programming reactive programming and reactive extension provide development model to tame the asynchronous beast so this using asynchronous and combining the power of reactive programming and PHP is the good approach to create modern PHP application and using reactive programming does not transform our system into a reactive system because reactive system are the next level this is a short example for reactive system this is maybe a confusion part using reactive programming does not build a reactive system reactive system as define reactive manifesto or an accurate architectural style to build responsive distributed system reactive system could be seen as distributed system don't write reactive system is characterized by four properties the first responsive reactive system needs to handle request in reasonable time and there is a reason reactive system must stay responsive in the phase of failures if it crash timeout or 500 error so it must be designed for failures and deal with them appropriately and scalable reactive system must stay responsive under various load consequently it must scale up and down and be able to handle the load with minimal resource and even driven components from reactive system interact using asynchronous messaging phase okay this is the result i use for learning reactive programming and you can use this resource also there is a php reactive programming book from martin scora and learning even driven PHP with reactive PHP book from serji zerg and from the reactive x website http rektvx.io thank you is there any question or you can also take the code from this prepostery for this slide this is the example of rx php okay we can take one question do we have any one who has a question for dolly no yes yeah thank you dolly