HTTP component<\/a> to make an asynchronous request.<\/p>\n\r\n$app = new FrameworkXApp();\r\n$app->get('\/', function () {\r\n echo \"Startn\";\r\n (new ReactHttpBrowser())\r\n ->get('https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts')\r\n ->then(function () {\r\n echo \"End (API)n\";\r\n });\r\n echo \"Endn\";\r\n\r\n return ReactHttpMessageResponse::plaintext(\"Hello world!n\");\r\n});\r\n$app->run();\r\n<\/pre>\nNormally, an external API request would block the page from rendering until the request completes. However, with the asynchronous operations that the ReactPHP HTTP component handles, the page loads instantly, as evidenced by the log.<\/p>\n <\/figure>\nThis makes FrameworkX capable of handling many more concurrent requests than traditional PHP setups, significantly speeding up page load times. But how fast is it?<\/p>\n
Speed<\/h4>\n I tested FrameworkX<\/strong> on a basic, inexpensive DigitalOcean droplet with 1 vCPU and 1GB of RAM. It handled around 4,000 requests per second effortlessly.<\/p>\n\r\nConcurrency Level: 50\r\nTime taken for tests: 22.636 seconds\r\nComplete requests: 100000\r\nFailed requests: 0\r\nKeep-Alive requests: 100000\r\nTotal transferred: 17400000 bytes\r\nHTML transferred: 1300000 bytes\r\nRequests per second: 4417.69 [#\/sec] (mean)\r\nTime per request: 11.318 [ms] (mean)\r\nTime per request: 0.226 [ms] (mean, across all concurrent requests)\r\nTransfer rate: 750.66 [Kbytes\/sec] received\r\n<\/pre>\nEven with additional workload, like disk read operations and rendering 100 lists from a JSON file, it still managed around 2700 requests per second.<\/p>\n
\r\nConcurrency Level: 50\r\nTime taken for tests: 36.381 seconds\r\nComplete requests: 100000\r\nFailed requests: 0\r\nKeep-Alive requests: 100000\r\nTotal transferred: 296700000 bytes\r\nHTML transferred: 280500000 bytes\r\nRequests per second: 2748.72 [#\/sec] (mean)\r\nTime per request: 18.190 [ms] (mean)\r\nTime per request: 0.364 [ms] (mean, across all concurrent requests)\r\nTransfer rate: 7964.31 [Kbytes\/sec] received\r\n<\/pre>\nI\u2019m pretty sure it could be much faster with better server specifications.<\/p>\n
Wrapping Up<\/h4>\n FrameworkX<\/strong> is a powerful, lightweight microframework for PHP. It runs asynchronously and is capable of handling multiple tasks efficiently, similar to Node.js. It\u2019s the perfect framework whether you\u2019re building a simple app or complex high-concurrency or real-time applications.<\/p>\nThe post Introduction to FrameworkX<\/a> appeared first on Hongkiat<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"PHP has come a long way and continues to improve with new features, syntax, and speed. The ecosystem is also expanding, with many developers creating frameworks to simplify the lives of other developers. Popular, full-featured frameworks like Laravel and Symfony exist, as do lightweight microframeworks like FrameworkX. It is a lightweight microframework for PHP that […]<\/p>\n","protected":false},"author":1,"featured_media":411,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-408","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts\/408"}],"collection":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/comments?post=408"}],"version-history":[{"count":3,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts\/408\/revisions"}],"predecessor-version":[{"id":418,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts\/408\/revisions\/418"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/media\/411"}],"wp:attachment":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/media?parent=408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/categories?post=408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/tags?post=408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}