{"id":32570446,"url":"https://github.com/ericmann/phptek-2025-demo","last_synced_at":"2025-10-29T08:16:57.021Z","repository":{"id":293925504,"uuid":"985512835","full_name":"ericmann/phptek-2025-demo","owner":"ericmann","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-18T00:09:20.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T18:55:09.127Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-17T23:27:44.000Z","updated_at":"2025-05-18T00:09:23.000Z","dependencies_parsed_at":"2025-05-18T01:34:38.746Z","dependency_job_id":null,"html_url":"https://github.com/ericmann/phptek-2025-demo","commit_stats":null,"previous_names":["ericmann/phptek-2025-demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ericmann/phptek-2025-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmann%2Fphptek-2025-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmann%2Fphptek-2025-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmann%2Fphptek-2025-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmann%2Fphptek-2025-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericmann","download_url":"https://codeload.github.com/ericmann/phptek-2025-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmann%2Fphptek-2025-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281585471,"owners_count":26526298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-29T02:00:06.901Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-29T08:16:03.553Z","updated_at":"2025-10-29T08:16:57.014Z","avatar_url":"https://github.com/ericmann.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Concurrency Demo: Sequential vs. Concurrent Requests\n\nThis demo illustrates the performance difference between fetching multiple web pages sequentially versus concurrently using PHP's `amp/http-client`.\n\n## Purpose\n\nThe goal is to showcase how asynchronous programming can significantly reduce the total time required to perform multiple I/O-bound operations, such as fetching data from several websites. This is particularly relevant in web applications where responsiveness and speed are critical.\n\n## Files\n\n*   `sequential.php`: Fetches the content of multiple websites one after the other. It uses `file_get_contents()` to retrieve the content and measures the time taken for each request and the total time.\n\n*   `concurrent.php`: Fetches the content of the same websites concurrently using `amp/http-client`. It creates an array of Futures, each representing an asynchronous request. The script then awaits all requests to complete, measuring the time taken for each and the total time.\n\n*   `fibers.php`: Demonstrates PHP Fibers, a low-level concurrency primitive introduced in PHP 8.1. The script shows how a Fiber can be started, suspended, and resumed, allowing manual control over execution flow. This is useful for understanding the building blocks of async frameworks like Amp.\n\n## Setup\n\n1.  **Install PHP:** Ensure you have PHP 8.3 or higher installed.\n2.  **Install Dependencies:** Navigate to the project directory in your terminal and run:\n\n    ```bash\n    composer install\n    ```\n\n    This will install the required `amphp/http-client` library.\n\n## Usage\n\n1.  **Run Sequential Script:**\n\n    ```bash\n    php sequential.php\n    ```\n\n    This will output the time taken to fetch each website's content sequentially, along with the total time.\n\n2.  **Run Concurrent Script:**\n\n    ```bash\n    php concurrent.php\n    ```\n\n    This will output the time taken to fetch each website's content concurrently, along with the total time.\n\n3.  **Run Fiber Demo Script:**\n\n    ```bash\n    php fibers.php\n    ```\n\n    This will demonstrate the usage of PHP Fibers, showing how they can be started, suspended, and resumed.\n\n## Expected Results\n\nYou should observe that the `concurrent.php` script completes significantly faster than the `sequential.php` script. This is because the concurrent script can fetch multiple web pages simultaneously, while the sequential script must wait for each request to complete before starting the next.\n\n## Notes\n\n*   Some websites may block requests from scripts like `file_get_contents()` or `amp/http-client` if proper headers (like `User-Agent`) are not set or if they detect bot-like behavior.\n*   The performance gain from concurrency will be more noticeable with a larger number of URLs and websites with higher latency.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericmann%2Fphptek-2025-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericmann%2Fphptek-2025-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericmann%2Fphptek-2025-demo/lists"}