Jump to content

Php From Command Line - Input Methods


bittiez

Recommended Posts

So, I've been using php off and on for years(I am by far not any type of expert, everything I know is self taught and I still have much to learn).

Yesterday I discovered that you can run php from a command line, It never even crossed my mind to even wonder if this was possible, so I'm very pleased that I found out it is!

 

I'm currently writing a simple command-line irc client, so far so good.

 

Right now I have only found one method of user input to the script and that's using this method:

fwrite(STDOUTm, "blah blah");

$blah = fgets(STDIN);

 

Which works well for certain things, however the problem is this pauses the script, and only accepts input when you run this code in the script.

 

I'm wondering if there is anyway to get input without stopping the script(It can be from another script).

 

$_POST would work perfectly, except one problem:

The script is constantly running, it doesn't stop, when you post something to a script, it creates a new "instance" of the script, meaning If this script is already running I can't get any $_POST data to it.

 

I'm hoping there is something I can do, and hoping you guys have some ideas.

My other idea is this:

Have my main script (this one) check a database or a file every loop (There is a while loop that loops over constantly while connected to the server), and if there is data than I can manipulate that data as needed.

Now, this would work okay but I'm hoping to avoid this so I don't need to go to all the extra hassle that would cause, and it seems very unnecessary if I can avoid it.

 

So any ideas or input would be greatly appreciated!

Link to comment
Share on other sites

I can't seem to find anywhere that shows it supports STDIN..

 

Do you think it would be possible for my script to connect to two places(different sockets), first the irc server and then another script(server) that I can send commands to the original with?

 

For example:

 

main script

IRC and ServerScript

 

then I used ServerScript to send data to main script, all the while main script just checks to see if its recieved any data from the serverscript..

 

Hmm this seems like it would work, does php accept socket connects like a server or can it only connect?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.