Skip to content

fix: prevent hanging when script is piped through curl#12

Merged
ivangrynenko merged 6 commits intomainfrom
fix/curl-pipe-hanging
Aug 20, 2025
Merged

fix: prevent hanging when script is piped through curl#12
ivangrynenko merged 6 commits intomainfrom
fix/curl-pipe-hanging

Conversation

@ivangrynenko
Copy link
Copy Markdown
Owner

Summary

This PR completes the fix for the curl piping issue by preventing PHP from hanging after the script completes.

Problem

Even after PR #11 was merged, the installer would still hang when piped through curl. The script would execute successfully (showing "Installation completed successfully!") but wouldn't exit cleanly, requiring users to press Ctrl+C.

Root Cause

When piped through curl, PHP's STDIN remains open after the script finishes, causing PHP to wait for more input indefinitely.

Solution

Added cleanup code before exit:

  1. Flush all output buffers to ensure messages are displayed
  2. Close STDIN explicitly with fclose(STDIN) to signal PHP that no more input is expected
  3. This allows the script to exit cleanly without hanging

Test Results

curl -s URL | php - Shows warning and installs core rules, exits cleanly
curl -s URL | php -- --ws - Installs web stack rules, exits cleanly
curl -s URL | php -- --help - Shows help and exits cleanly
✅ Direct execution still works: php install.php

Why Tests Didn't Catch This

The existing test suite only tests direct PHP execution (php install.php ...) and never tests the piped scenario (cat install.php | php). This is a gap in test coverage that should be addressed in a future PR.

Files Changed

  • install.php: Added STDIN cleanup before exit (lines 1136-1145)

- Added fclose(STDIN) before exit to prevent PHP from waiting for more input
- Added flush() calls to ensure all output is sent before exit
- This fixes the hanging issue when using curl | php piping
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @ivangrynenko, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where the PHP installer script would hang indefinitely when executed by piping its content through curl. The core problem was identified as PHP's standard input (STDIN) stream remaining open after the script's execution, causing the process to wait for further input. The solution involves adding cleanup code to install.php that ensures all output buffers are flushed and, crucially, that the STDIN stream is explicitly closed before the script exits. This allows the script to terminate cleanly, improving the user experience for installations via curl.

Highlights

  • PHP Script Exit Behavior: Implemented a fix in install.php to prevent the script from hanging when piped through curl by explicitly flushing output buffers and closing STDIN before exiting.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the hanging issue when the installer script is piped through curl. The solution of flushing output buffers and explicitly closing STDIN is correct. I've added a couple of suggestions for improvement: one to make the output flushing more robust for nested buffers, and another regarding an auto-generated file that seems to have been unintentionally included in the changes. Overall, this is a good fix.

Comment on lines +1 to +11
# Cursor Rules Installation

## Version 1.0.5 - 2025-01-03
**Version:** 1.0.5
**Installation Date:** 2025-08-20 09:12:08 UTC
**Rules Installed:** 7 files

### Major Updates to Pull Request Review Instructions
## Installation Type
- Core rules (default)

**Enhanced Multi-Language Support:**
- Added comprehensive support for all languages in cursor rules (PHP, Python, JavaScript, TypeScript, CSS, HTML)
- Implemented language-specific coding standards and security practices
- Added framework-specific guidelines (Drupal, Django, React, Vue.js, Express.js)

**Large File Detection and Skipping:**
- Added logic to skip compiled/minified files (>1MB, *.min.*, *-bundle.*, etc.)
- Implemented vendor directory filtering (node_modules/, vendor/, dist/, build/)
- Added auto-generated file detection to focus on source code only

**Improved Security Assessment:**
- Language-specific security checks (SQL injection, XSS, command injection)
- Framework-aware security considerations
- OWASP compliance across all supported languages

**Enhanced Label Management:**
- Added language-specific labels (lang/php, lang/python, lang/javascript, etc.)
- Automatic language detection based on file extensions
- Technology-specific colour coding using official language colours

**Technology Detection Process:**
- File extension analysis for automatic language identification
- Framework detection through config files (package.json, composer.json, etc.)
- Project structure analysis for framework patterns
- Dependency analysis and build tool detection

**Updated Review Checklist:**
- File analysis requirements with mandatory large file skipping
- Language-specific sections for targeted reviews
- Enhanced security focus across all technologies
- Performance considerations for each language

**File:** `new-pull-request.mdc`
**Impact:** Major enhancement to code review capabilities across all supported languages
**Breaking Changes:** None - backward compatible

---

## Previous Versions

### Version 1.0.4
- Previous version (details to be added)

### Version 1.0.3
- Previous version (details to be added)

### Version 1.0.2
- Previous version (details to be added)

### Version 1.0.1
- Previous version (details to be added)

### Version 1.0.0
- Initial release No newline at end of file
## Source
Rules downloaded from: https://github.com/ivangrynenko/cursor-rules
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This file appears to be an auto-generated installation report created by the install.php script. Its content has completely changed from a changelog to a report, which seems like an artifact from testing the installer. Including auto-generated files that change on each run can add noise to the repository's history.

Could you please confirm if this change is intentional? If not, it might be best to revert the changes to this file to keep the pull request focused on the bug fix.

Comment on lines +1137 to +1140
if (ob_get_level() > 0) {
ob_flush();
}
flush();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Your current implementation for flushing output buffers only handles the topmost buffer. If there are nested output buffers (which can sometimes be started by PHP extensions or framework components), this might not flush all pending output before the script exits. A more robust approach is to use a while loop with ob_end_flush() to ensure all buffer levels are flushed and closed.

  while (ob_get_level() > 0) {
    ob_end_flush();
  }
  flush();

- Added AGENTS.md Created field with date 2025-08-20
- This tracks when the AGENTS.md documentation was generated
- Added new section for AGENTS.md documentation
- Version 1.0.6
- Created date: 2025-08-20
- Describes the comprehensive guide features
- Removed incorrectly added AGENTS.md section
- UPDATE.md is an installation history file that should not be modified
- File now contains only the original installation record
- Restored the correct updates history file from main
- This file tracks version history, not installation records
- Added version 1.0.6 entry dated 2025-08-20
- Documented AGENTS.md documentation addition
- Listed installer improvements and bug fixes
- Noted curl piping fixes and STDIN handling improvements
@ivangrynenko ivangrynenko merged commit 8b89d88 into main Aug 20, 2025
1 check passed
ivangrynenko added a commit that referenced this pull request Sep 1, 2025
fix: prevent hanging when script is piped through curl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant