{"id":23988753,"url":"https://github.com/paulnovack/cppzeromqasynchsqlserver","last_synced_at":"2026-06-12T13:31:03.234Z","repository":{"id":269746127,"uuid":"908342963","full_name":"PaulNovack/CppZeroMQAsynchSQLServer","owner":"PaulNovack","description":"c++ server for implementing asynchronous queries for PHP web Apps","archived":false,"fork":false,"pushed_at":"2024-12-29T16:38:52.000Z","size":1298,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T03:12:55.713Z","etag":null,"topics":["asynchronous-programming","php-framework","sql","zeromq"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PaulNovack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-12-25T19:56:52.000Z","updated_at":"2024-12-29T16:38:55.000Z","dependencies_parsed_at":"2024-12-25T20:27:23.913Z","dependency_job_id":"995da775-e663-4664-9bc5-54c9527dff9e","html_url":"https://github.com/PaulNovack/CppZeroMQAsynchSQLServer","commit_stats":null,"previous_names":["paulnovack/cppzeromqasynchsqlserver"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PaulNovack/CppZeroMQAsynchSQLServer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulNovack%2FCppZeroMQAsynchSQLServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulNovack%2FCppZeroMQAsynchSQLServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulNovack%2FCppZeroMQAsynchSQLServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulNovack%2FCppZeroMQAsynchSQLServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PaulNovack","download_url":"https://codeload.github.com/PaulNovack/CppZeroMQAsynchSQLServer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulNovack%2FCppZeroMQAsynchSQLServer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34247460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"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":["asynchronous-programming","php-framework","sql","zeromq"],"created_at":"2025-01-07T16:15:28.769Z","updated_at":"2026-06-12T13:31:03.212Z","avatar_url":"https://github.com/PaulNovack.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Adding Asynchronous Querying to PHP with C++ ZeroMQ and mySQL Server\n\n## Introduction\n\nIn modern web development, achieving efficient and scalable systems often requires handling asynchronous operations. PHP, traditionally synchronous in nature, has seen efforts to introduce asynchronous capabilities. One such approach leverages a combination of a C++ ZeroMQ server for managing SQL queries asynchronously and integrating this system with PHP frameworks like Symfony and Laravel. This README explores the benefits of asynchronous querying for PHP applications and how it can be seamlessly integrated into Symfony and Laravel by modifying Doctrine and Eloquent ORM.\n\n## Understanding the Role of Asynchronous Querying\n\n### The Problem with Synchronous SQL Queries in PHP\n\nPHP applications generally execute SQL queries synchronously, waiting for the query to complete before continuing with other operations. This approach limits performance and scalability, especially when:\n\n- Queries involve complex joins or aggregations.\n- The database is under heavy load.\n- Real-time or near-real-time responses are required.\n\nThis synchronous behavior increases latency and reduces the number of concurrent requests a PHP application can handle.\n\n### Why Asynchronous Querying?\n\nAsynchronous querying allows applications to send SQL queries and continue executing other code without waiting for the database response. This capability:\n\n1. **Improves Performance:** Non-blocking queries enable applications to handle more requests simultaneously.\n2. **Enhances Scalability:** Resources are utilized more efficiently, especially in high-traffic scenarios.\n3. **Enables Real-time Applications:** Applications such as chat systems, live dashboards, and notifications benefit significantly from asynchronous operations.\n\n## Overview of `CppZeroMQAsynchSQLServer`\n\nThe `CppZeroMQAsynchSQLServer` repository demonstrates a robust way to implement asynchronous querying in PHP. Built using C++, ZeroMQ, and MySQL, the server processes SQL queries sent via ZeroMQ, executes them, and returns the results asynchronously.\n\n### Key Features\n\n1. **ZeroMQ for Communication:** Leverages ZeroMQ’s high-performance message queuing capabilities to manage communication between the server and clients.\n2. **Asynchronous Query Handling:** Processes multiple queries simultaneously using a thread pool.\n3. **Message Pack Response Format:** Responses are returned in message pack, making them easy to integrate with PHP frameworks.\n4. **Connection Pooling:** Efficient management of database connections ensures optimal resource utilization.\n\n### How It Works\n\n- **Client Side:** PHP sends a query request to the C++ server via ZeroMQ asynchronously non blocking allows the PHP Application to perform other operations.\n- **Server Side:** The C++ server receives the query, executes it asynchronously, and sends back the result.\n- **PHP Integration:** The response is handled then synchronously in PHP, enabling the application to process the data when it arrives.\n\n## Integration into Symfony and Laravel\n\n### Modifying Doctrine\n\nTo integrate asynchronous querying into Symfony, extend Doctrine’s Query Builder:\n\n```php\n        /** @var CustomRepository $repository */\n        $repository = $doctrine-\u003egetRepository(Product::class);\n        $repository-\u003eaSearchByName($searchTerm);\n        // Do other work here query is executing on server aSearchByName() is non blocking\n\n\n        // Get results back from server blocking get results\n        $products = $repository-\u003eaSyncFetch();\n        return $this-\u003erender('product/list.html.twig', [\n            'products' =\u003e $products\n        ]);\n```\nAn example Symfony implementation is here: https://github.com/PaulNovack/symfony_async\n\n### Modifying Eloquent\n\nFor Laravel, extend Eloquent’s query builder:\n\n```php\n        $user = new User();\n        $user-\u003eaFetchAll();\n        // Do other work here query is executing on server aFetchAll() is non blocking\n\n        // Get results back from server blocking get results\n        $users = $user-\u003eaFetchResults();\n        return view('users.index', compact('users'));\n```\nAn example Laravel implementation is here: https://github.com/PaulNovack/laravel_async\n\n## Benefits of Asynchronous Querying\n\n1. **Reduced Latency:** Applications can start processing other tasks while waiting for query results.\n2. **Scalable Architecture:** Asynchronous operations reduce thread blocking, enabling more efficient resource utilization.\n3. **Enhanced User Experience:** Faster responses and real-time updates improve overall user satisfaction.\n4. **Flexibility:** Enables integration with modern event-driven paradigms, aligning PHP with trends in web development.\n\n## Challenges and Considerations\n\n1. **Debugging Complexity:** Debugging asynchronous code can be challenging due to its non-linear flow.\n2. **Learning Curve:** Developers need to understand event loops, promises, and asynchronous programming.\n3. **Server Setup:** Deploying and managing a C++ ZeroMQ server requires expertise beyond standard PHP environments.\n4. **Compatibility:** Ensuring compatibility with existing database drivers and connection pooling mechanisms is essential.\n\n## Real example\n\nBuild all the containers: \"docker-compose -f docker-compose.yml up --build\"\n\nSometimes the build will fail if the copy command does not complete before MakeFile runs if this happens run: \"docker system prune -a\"\n\nThen run build command again if it failed.\n\nIn the app direcory of the project there are 2 files that can be run under apache:  standard.php and zeromq.php.\n\n\nYou can access these files at: http://127.0.0.1:8080/standard.php  and  http://127.0.0.1:8080/zeromq.php once you see the containers have built and the message \n\ncpp_server               | Database initialized and 500000 users added.\n\ncpp_server               | Server is running on tcp://0.0.0.0:5555\n\n\nThe standard.php runs 25 select queries at random offset retrieving 100 records each query and simply outputs the sql statements usng standard mysql connector.\n\nThe zeromq.php rund the same outputting the same information but uses zeroMQ and the cpp_server to run the queries asynchronously.\n\nThe zeroMQ version using asynch queries runs about 650% faster than the synchronous version.\n\nstandard.php output:  Takes about 813 milliseconds\n\n![screenshot](standard-php.png)\n\nzeromq.php output:   Takes about 124 milliseconds\n\n![screenshot](zeromq-php.png)\n\n## Conclusion\n\nIntroducing asynchronous querying to PHP through a C++ ZeroMQ SQL server unlocks significant performance and scalability benefits. By modifying Doctrine and Eloquent, frameworks like Symfony and Laravel can seamlessly integrate this capability, enabling developers to build modern, real-time, and scalable applications.\n\nWhile challenges exist, the potential benefits make this approach worth exploring. Asynchronous querying is a natural evolution for PHP, aligning it with modern web development trends and ensuring its relevance in the era of high-performance applications.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulnovack%2Fcppzeromqasynchsqlserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulnovack%2Fcppzeromqasynchsqlserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulnovack%2Fcppzeromqasynchsqlserver/lists"}