Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 944907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:40:12+00:00 2026-05-15T22:40:12+00:00

Question 1 I used to use that line for my PHP parser file for

  • 0

Question 1

I used to use that line for my PHP parser file for a game server, but it does not work anymore. I know there is the fopen("php://stdin") thing but that’s now 3 lines of code instead of just one, why would PHP do this?

Question 2

Also, when I use that method I keep getting this output which is causing my script to not read the commands the parser outputs, how can I stop it?

X-Powered-By: PHP/5.2.12
Content-type: text/html

I tried setting Content-Type to text/plain and it didn’t do anything…
Here’s the base code:

#!/usr/bin/php
<?php

while (1):
    $line = rtrim(fgets(STDIN, 1024));
    $line = explode(" ", $line);
    switch ($line[0]):
        // NEW_ROUND <date> <time>
        // PLAYER_ENTERED <nice_name> <ip> <real_name>
        case "PLAYER_ENTERED":
            print "PLAYER_MESSAGE {$line[1]} WELCOME TO TRONNERS!\n";
            break;
        // PLAYER_LEFT <nice_name> <ip>
        // RACE_DONE
        case "RACE_DONE":
            print "CONSOLE_MESSAGE RACING TIMEKEEPER COMING SOON!\n";
            break;
        // ROUND_COMMENCING <round> <max_rounds>
        case "ROUND_COMMENCING":
            print "CENTER_MESSAGE What's the name of this map?\n";
            break;
    endswitch;
endwhile;

?>

I’m using a tail to keep lines being posted to a file going into the PHP parser and then the output from the parsed is being sent to another commands file via tee.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:40:13+00:00Added an answer on May 15, 2026 at 10:40 pm

    You are using the *-cgi binary from the command line, which I wouldn’t recommend. Use the CLI one if available. See where the symbolic link in /usr/bin/php actually goes.

    edit: aha, here it is in the manual, only valid for CLI:

    http://www.php.net/manual/en/features.commandline.io-streams.php

    $ echo  '<?php echo fread(STDIN,123); ?>' > r.php
    $ echo 'bla' | php5-cgi -q -d html_errors=off r.php 
    Warning: fread() expects parameter 1 to be resource, string given in /tmp/r.php on line 1
    Call Stack:
        0.0002     330080   1. {main}() /tmp/r.php:0
        0.0002     330260   2. fread() /tmp/r.php:1
    
    $ echo 'bla' | php r.php 
    bla
    

    Under debian it could likely be fixed by the following (don’t know about other *nix flavors):

    update-alternatives --config php
    

    For building from source the manual explains what happens: http://nl.php.net/manual/en/features.commandline.introduction.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.