bittiez Posted October 25, 2012 Share Posted October 25, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/269881-php-from-command-line-input-methods/ Share on other sites More sharing options...
kicken Posted October 25, 2012 Share Posted October 25, 2012 Depending on what your needs are using stream_select may allow you to to other processing while waiting for user input. I've never tried it with the STDIN stream though, only sockets. There is also the readline and ncurses extensions that you may find handy for CLI development. Quote Link to comment https://forums.phpfreaks.com/topic/269881-php-from-command-line-input-methods/#findComment-1387600 Share on other sites More sharing options...
bittiez Posted October 25, 2012 Author Share Posted October 25, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/269881-php-from-command-line-input-methods/#findComment-1387601 Share on other sites More sharing options...
kicken Posted October 25, 2012 Share Posted October 25, 2012 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? Sure, you could do that. stream_socket_server Quote Link to comment https://forums.phpfreaks.com/topic/269881-php-from-command-line-input-methods/#findComment-1387602 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.