Michdd Posted August 13, 2009 Share Posted August 13, 2009 I've never done anything like this, as I didn't even know it was possible. Is it much more complicated than just compiling it and then running it on a computer with a internet connection? Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/ Share on other sites More sharing options...
benphelps Posted August 14, 2009 Share Posted August 14, 2009 When you say, console apps, I think you have a misunderstanding of how it works. PHP is not a compile and distribute language like C. PHP requires an interpreter before it can do anything. To run a PHP script in the command line, you can start it via "php script.php". When in the CMD line you loose most Superglobals and gain a few you dont have access to while not in the CMD line. I know you gain "$argv" and "$argc". You loose $_SERVER $_GET $_POST $_COOKIE $_FILES as those are set all by Apache or w/e server software is being used. Now, there are some tools you can use that CAN compile PHP with the PHP interpreter. The one i use is called Bambalam, a little old (PHP4) but it does the job. http://www.bambalam.se/bamcompile/ As far as what you can do while in the CMD line, I have personally coded a VERY basic, but functioning HTTP server. I have also coded an IRC bot in PHP. There are some very fun projects you can do with sockets and PHP. Hope this all helps a little. Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-897811 Share on other sites More sharing options...
Michdd Posted August 14, 2009 Author Share Posted August 14, 2009 No, I don't misunderstand how PHP works I've been using PHP for a very long time, I just read that it's also possible to compile PHP into stand-alone applications. So I was talking about what you said later in your post. I actually found something called PriadoBlender myself which works well, and it does supporting compiling for PHP5 and PHP4. Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-897836 Share on other sites More sharing options...
kratsg Posted August 14, 2009 Share Posted August 14, 2009 I'm actually quite amused by this post. In fact, I never really thought of PHP that way, although I did assume that it could have been possible. Is there any limit or differences in the functionality of having a C++ console app versus a PHP console app? Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-897837 Share on other sites More sharing options...
roopurt18 Posted August 14, 2009 Share Posted August 14, 2009 I'm actually quite amused by this post. In fact, I never really thought of PHP that way, although I did assume that it could have been possible. Is there any limit or differences in the functionality of having a C++ console app versus a PHP console app? You are limited to what extensions and / or libraries exist for the language. But in principle they are much the same. I write quite a few command line PHP programs for work. Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-897868 Share on other sites More sharing options...
corbin Posted August 14, 2009 Share Posted August 14, 2009 I write PHP CLI programs quite often. In fact, I would say I write a couple a day. I write big ones every now and then (back when I used to do some stuff that involved parsing some very interestingly laid out files I used to write fairly complex CLI applications in PHP). But yeah, as roopurt said, scripting for PHP running through CLI and through a web interface is very, very similar. As for a compiler (in the sense of compiling to machine code), I've never found one that wasn't missing some features, but the last time I looked was a few years ago. Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-897876 Share on other sites More sharing options...
Michdd Posted August 14, 2009 Author Share Posted August 14, 2009 I'm actually quite amused by this post. In fact, I never really thought of PHP that way, although I did assume that it could have been possible. Is there any limit or differences in the functionality of having a C++ console app versus a PHP console app? You are limited to what extensions and / or libraries exist for the language. But in principle they are much the same. I write quite a few command line PHP programs for work. What about performance and speed differences? Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-897909 Share on other sites More sharing options...
Michdd Posted August 14, 2009 Author Share Posted August 14, 2009 Oh, one other question.. Is it possible to have user input with one of this console applications? I'm pretty sure it's not, just making sure. Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-897918 Share on other sites More sharing options...
roopurt18 Posted August 14, 2009 Share Posted August 14, 2009 Performance and speed will be based on just how the PHP code is "compiled." Compiled code always executes faster than interpreted code, so it depends on if the PHP "compiler" actually compiles the code or not. That said PHP is extremely fast. I've written a PHP program that loops over 9 million MS SQL records, performs a little arithmetic, and it finished in probably less than two minutes. You can also have user input. On Windows with COM you can also accept strings of text such as passwords in a manner that the user's input will not appear on the screen. Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-898314 Share on other sites More sharing options...
Michdd Posted August 14, 2009 Author Share Posted August 14, 2009 Do you know of any websites that explains how to accept user input in a PHP compiled console application? I couldn't seem to find anything myself. Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-898372 Share on other sites More sharing options...
Daniel0 Posted August 14, 2009 Share Posted August 14, 2009 Just read data from the STDIN stream. Like trim(fgets(STDIN)) for instance. Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-898385 Share on other sites More sharing options...
Michdd Posted August 14, 2009 Author Share Posted August 14, 2009 Just read data from the STDIN stream. Like trim(fgets(STDIN)) for instance. I'm not sure I understand what you mean :| Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-898400 Share on other sites More sharing options...
Daniel0 Posted August 14, 2009 Share Posted August 14, 2009 In that case we are so fortunate that there is a search function on PHP.net: http://php.net/results.php?q=stdin&p=manual Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-898401 Share on other sites More sharing options...
Michdd Posted August 14, 2009 Author Share Posted August 14, 2009 In that case we are so fortunate that there is a search function on PHP.net: http://php.net/results.php?q=stdin&p=manual Okay, I've done some research.. I found something will work like this: #!/usr/bin/php -q <?php /* Define STDIN in case if it is not already defined by PHP for some reason */ if(!defined("STDIN")) { define("STDIN", fopen('php://stdin','r')); } echo "Hello! What is your name (enter below):\n"; $strName = fread(STDIN, 80); // Read up to 80 characters or a newline echo 'Hello ' , $strName , "\n"; ?> However, this is PHP CLI, so it would be running it from the command line. Which isn't exactly what I'm doing. I'm using PriadoBlender to compile it is a .exe. Is it possible to allow user input from the compiled .exe? Edit: Nevermind it was a stupid problem, I solved it. Thanks for all your help. I got one last question, how can I make the program 'pause' when it's done instead of closing right away? I know I can run the program through the command line to get this effect, but it's kinda inconvenient. Edit Edit: Never mind, it's the same as in C++, system("PAUSE"); thanks for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/170185-solved-php-console-apps/#findComment-898451 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.