PHP Only Runs From Command Line
I know very little about PHP, but I was just curious to know
why exactly would some PHP code run fine from the command line but not
from the browser?
I'm just curious. I was working with someone else's PHP code that
supposedly created MySQL tables in a database and for some reason it
just wouldn't create the tables at all (no specific error message).
Someone suggested I run from the command line and when I did, it
worked...
View Complete Forum Thread with Replies
Related Forum Messages:
CLI ( Command-line ) PHP Displaying Source Code In-line When Programis Executed
I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. Everything has been running flawlessly without problems. Very amazing to use VMware, it has worked beautifully. uname -a Linux xxxxxxx 2.6.13-15.8-default #1 Tue Feb 7 11:07:24 UTC 2006 i686 i686 i386 GNU/Linux php -v PHP 4.4.2 (cli) (built: Feb 7 2006 20:13:29) Copyright (c) 1997-2006 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies php -m [PHP Modules] bcmath bz2 calendar ctype curl dbx dio domxml exif ftp gd gettext gmp iconv mcrypt mssql mysql ncurses openssl overload pcre posix session shmop sockets standard sysvsem sysvshm tokenizer wddx xml yp zlib When I run the following program from the command line it prints out the source code as well as the output from the program. I run other PHP programs on the command-line and this doesn't happen. It's really peculiar. The error output is below. I copied this off of php.net, and have modified it only slightly to allow command-line input. I was trying to find a CSV solution, which I ended up finding elsewhere, but am curious why this program would error out the way it does--have I misconfigured something? My php.ini is basically unchanged, if at all. I think I might have set the path to mysql but that's about it. When I run this program from the web it works without error. <?php if ( $argv[0] ) { $file = $argv[0] ; } else{ $file = $_GET['file'] ; print "<font face=arial> " ; } $row = 1; $handle = fopen("$file", "r"); while ( ( $data = fgetcsv($handle, 1000, ",") ) !== FALSE ) { $num = count($data); print "$num fields in line $row:<br> "; $row++; for ($c = 0; $c < $num; $c++) { print "$data[$c]<br> " ;
View Replies !
Run From Command Line
I just installed the latest version of PHP as an Apache Module. I'm wondering, how can I now run PHP from the command line? I heard there was a way without having to reinstall PHP to do this.
View Replies !
PHP Command Line (php.exe)
I am running WAMP Server on my computer, and I need to run a script with the PHP Command Line Interface... I've been doing some research and so I tried entering the folowing command into the php command window: php -h, that is supposed to show a list of commands... nut it does nothing... nothing I try works... any ideas?
View Replies !
Command Line?
i'm currently running easyphp1.7 on win98. i've read that php4.3 comes with pear package installer but under windows this is not installed automatically. apparently you need the command line to install this? where do i find the php command line?
View Replies !
OOP In Command Line
I'm trying to write a fairly simple, easy to reconfigure php script which must be run from the command line, in this case, of a windows machine. I am defining my variables in a file called 'config.php' and i am requiring config.php at the top of the script (first thing i do). When i go to execute the script from the command line, it simply echos the contents of config.php in the command prompt.
View Replies !
Command Line
I need to run php script from command line for debugging. I also need to pass a GET string. How can I do this? I tried the following: $> php index.php q=test
View Replies !
Command Line From PHP
Im really struggling with this. Ive searched the web, but I still cant find anything that works. Im running on Windows XP Pro, IIS, and PHP 5.0.2. I have a test.bat(its located in the local directory that Im running the PHP script from) file that contains: Code: dir After searching around, Ive found a couple of people using exec() to execute a command. My php file: PHP Code: echo exec('test.bat'); exec('test.bat', $output); echo $output //Im trying both examples to see if one of them works.
View Replies !
Just One Line ! (exec Command)
I would most like to just get the first line from exec result. The last line just isn't what I want. When I use passthru it doesn't allow me to store the results in a variable, so that's no good.
View Replies !
Skip To Line Command?
Hello fellow PHPers. I've made a few posts in the past few days and really appreciate your help. Now i'm at the end of my project - getting a database submission/send email form to validate. I get all the correct errors if the person doesn't enter certain fields, and the data doesn't submit. If they do enter all the required fields, it submits... However, the code for when it doesn't submit reads... if ($errmsg!= "") { echo $errmsg; } else { the rest of the code the rest of the html syntax My problem is that if the error page comes up, the rest of the HTML doesn't get rendered because the PHP simply quits. Is there a command in PHP in terms of "Go To Line This in the document", so rather than exiting it would just skip the rest of the PHP but still print all the HTML. I thought of switching!= to == but the way in which that works fails as well. I'm thinking I might have to validate straight on the form rather than the submission page, but let me know what you know!
View Replies !
Talking To The Command Line
I have written a c program using Baltimores Encryption solution. I need to be able to access the executable from PHP but have not got the first clue how... I simply need to pass the executable a string, and expect a string back. The whole function works on the command line, but, AGGHHH, how to i integrate it into PHP... this is why i love ASP and COM URL.
View Replies !
Command Line Problems
I'm trying to use PHP as a command line executable, but I'm running into a few problems with passing in arguments, mainly, I can't. I am using PHP version 4.2.3 and I have installed it with --enable-cli. I can run PHP scripts from the command line, no problem. However, no matter what I try, I can't seem to pass in variables and print out their values.
View Replies !
Newbie: How To Run Php From Command Line?
I need to test a script and want to do so on a Linux box (logged in via SSH from another machine). I tried creating a test script (called "test.php") like this: #!/usr/bin/php <?php print "test"; ?> and tried running this from the command line like this: ../test.php but nothing happens. I also tried this: ../test test.txt and the text in test.txt is this: X-Powered-By: PHP/4.2.2 Content-type: text/html Why is "test" not appearing in the test.txt file? How do I get "test" to appear on my screen, rather than having to use test.txt? Do I have to redirect STDOUT? How do I do this?
View Replies !
Command Line Tool
How do I get php to run a command line tool, in Windows Server 2003, and the continue with the job in hand, is this possible?
View Replies !
Compiling Command-line
I'm trying to install a program (Cacti -- it queries for things like bandwidth usage, etc. every five seconds, and generates graphs from that data); however, it requires that it be able to run "php" from the command-line. (As opposed to through Apache.) Is there an easy way to recompile PHP with its previous settings, but also configure it to allow me to invoke it from the command line? (If it matters; I compiled it initially with ApacheToolbox, but that's of no help to me for this.)
View Replies !
PHP And Command Line (for Wiki)
I started to "program" in PHP (better say to read it :P) from a few days because I am installing a Wiki on a virtual server (Windows Server 2003 with Plesk 7.6). I have PHP5 and all is working just fine. However, I am trying to parse latex equations and encountered some troubles. I have already installed all the necessary software and when I execute the following by command line: C:miktexinlatex.exe --output-directory=C:Inetpubvhostsmysite.com httpdocswikiimages mp --interaction=nonstopmode C:a.tex I generate the right file in the right folder. However, when I try to execute (adding it to a PHP routine that is executed for sure): $command = "C:miktexinlatex.exe --output-directory=C:Inetpub vhostsmysite.comhttpdocswikiimages mp -- interaction=nonstopmode C:a.tex"; $text = exec($command);
View Replies !
Reading From Command Line
I want to be able to have an infinite loop that is exited when the user types "q" on the command line. This is pretty trivial: while(1) { if (trim(fgets(STDIN) == "q") { exit; }} The loop however holds and waits for user input. I searched the php.net site and in the user comments I found this function: Code:
View Replies !
Execute Command Line
Is it possible to execute a command line from php and then post the data to a variable or array in php. If it can be done i would be happy to see an example with "echo hello". I am running PHP5 on Linux.
View Replies !
Sql From A Command Line Sort Of
I have started an assignment for college, where I have to create a form to view fields from a MySQL database using PHP no problems there. The problem I have is another part of the assignment which requires me to be able to input a complete SQL command in via an input/textarea box. What the assignment has asked for is something similar to the SQL window as in PHPMyAdmin. What I need to know is how do I parse a complete string such as - SELECT * FROM table WHERE clause = CONDITION. I know it's easy enough embedding SQL into PHP, I don't have a problem with that at all, what I think I need to find out is how to parse all the redundant characters in the string, spaces etc.
View Replies !
Command Line With Out Setup
I need to run a script under windows server 2003, this script is only needs to connect to mssql 3 times a day and do something. I cannot run a setup (it doesn't matter y), so I downloaded the latest php folder from php.net and put it in c:/php. I was able to run php from command line with no problems, but i cant seem to find the php.ini to enable the mssql componnents. there is the php.ini-dist and php.ini-recommended renaming them wont help. any suggestions how to implement the php.ini without setup. BTW, i did not find any solution in the installation guide.
View Replies !
Command-line Interface
In the docs, it says the command-line executable (that allows you to run PHP scripts on your console as opposed to inside the web server) was introduced in 4.3.0. But I was told by someone that he can do command-line stuff with 4.1.0. Is anyone else using the command-line executable with a version earlier than 4.3.0?
View Replies !
PHP Arguments From The Command Line
I read somewhere a while back that arguments can be sent to a PHP 5 script through a cronjob via $_REQUEST in some format. I know that I could send them through 'argv' but what if the server configuration does not have "register_argc_argv" set? How would I setup the arguments on the command line to send them in with a key/value pairing that shows up in $_REQUEST?
View Replies !
Using A Script At Command Line
I'm way out of my depth on this one and I'm not even sure if it's possible. I have a script that runs daily collating statistical data on widgets, and I'd love to have the server automate a post to a pnphpBB2 forum. I've had a look at the source in the "post a new topic" page, and it seems that the "submit" button calls this:- Code:
View Replies !
Best Command Line Debugger
I'd like to be able to debug php scripts on the command line, going through the browser. In other words, set up the debugger to listen and then type in a url and have the code stop before displaying stuff to the browser. Then, step through each individual piece of code, etc, whilst having the output mirrored to either another file or the debugger screen.
View Replies !
Mysql Command Line Client
Is there any way of making the mysql command line client full-screen? Sometimes it's easier to use the client than go thru php, but since it's only about 80 characters wide that limits its usefulness.
View Replies !
Disable Command Line Arguments For Php-cli
i have been trying to disable the -n and -c arguments that you can use with php from the command prompt. this is because these features can effectively disable my php.ini which has a whole mess of disabled_functions (that i want to ensure remain disabled). my best idea for going about doing this so far has been to download the source for the newest php, with hopes to compile my own which will ignore arguments other than a filename. so far the closest i have got is to the the zend_API.c which has the follow function: Code:
View Replies !
Segmentation Fault On Command Line
I have a script running in the wee hours via cron job. When I access the script via browser it works like a charm. I noticed it was not succeeding and ran it manually from the command line and it threw a Segmentation Fault. Googling produces a ton of information on this subject but al of specific to certain binaries and it doesn't seem germaine to solving my problem. <? mysql_connect('mysql.example.com', 'example', 'example'); mysql_select_db('example'); mysql_query("DELETE FROM aniSessionLog WHERE timestamp < NOW() - 900"); $rows = mysql_affected_rows(); mail('jg@example.com', 'cleaned Intranet DB', "$rows rows deleted."); ?>
View Replies !
MySQL Database From The Command Line
I am creating a MySQL database from the command line for the first time. I am creating a database called 'goldminers' with 1 table called 'goldminers'. What am I doing wrong here: mysql> use goldminers Database changed mysql> drop table goldminers -> ; Query OK, 0 rows affected (0.13 sec) mysql> make table goldminers -> (id int unsigned not null primary key, -> name char(30) not null, -> dateIssued date not null, -> location char(20) not null, -> comment text null, -> url text null); ERROR 1064: You have an error in your SQL syntax near 'make table goldminers (id int unsigned not null primary key, name char(30) not n' at line 1 The reason that I didn't make the ID auto_increment is that, even though it is generally incrementing by 1 every time, there are some places where the database skips numbers because of goldminers who we don't have any information on. I need my database's IDs to match the IDs on the existing paper-version of the database.
View Replies !
Running PHP On Command Line & IIS Setup
I am trying to run PHP off of a IIS server....which hasn't be so pretty. I have included the path environment variable C:PHP, rebooted and started back up. Within C:PHP are two executables php-cgi.exe and php-win.exe. everything I have read online has said that all I need to do is point an environment path to this folder and everything should work. wrong!!!! I try to run a script in dos and get php is not valid command error.....it's as if it isn't recognizing the command path. I have also set up php under properties to be opened by the CLI....so what am I doing wrong here? I'm running IIS 6 with a dedicated server.
View Replies !
Sed Command Fails If Line Has Quote
I'm trying to make a script that will search a list of files and remove the following line <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> I'm doing this by generating a sed command and using system to execute it like so: $t = sprintf("%s "s/<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">%s/g" %s >%s", $sedPath,$str1_rpl, $infile, $outfile); system($t); The problem is the quote found in the text to be replaced. sed sees it as part of its command and ignores everything after it. For example, if I use <meta http-equiv="Content-Type" content= for the search string, it works. But if I use <meta http-equiv="Content-Type" content=" it doesn't work. I have tried escaping the quote
View Replies !
Php Designer 2007 Command Line
In windows XP, I want to be able to click on a .php file and have it opened in PHP Designer 2007, Or right-click on it and have an "edit" menu option presented to me. I know how to tweak the registry to do this in general, but what would the command line look like in this specific case ?
View Replies !
Speeding Up Command Line Scripts
I have a command line script which works really fine, the only problem is that it take *really* long for the first output to be printed on screen. Since I also get some HTTP headers I'm suspecting that some sort of output buffering is used. How can I tell PHP to flush the buffer automatically (without using flush(); after every print or echo) and to remove the headers?
View Replies !
Command-line PHP And Suppressing Headers - Help
How do I suppress the lines PHP normally delivers to stdout (your browser) if I am doing command-line PHP? e.g. stuff.php: <? echo 'Hello World' ?> Calling it from a Red Hat 7.3 command-line terminal I would do the following: php /my/directory/path/to/stuff.php And I would eventually get Hello World But before that, an enormous amount of garbage, particularly HTTP header information: PHP Version 4.2.3 Content-type: text/html Hello World How do I strip everything out except that which I need to see while using PHP from the command line? I am having a horrific time using TCL instead.
View Replies !
Syntax Check On The Command Line
It would be great if anyone could help me with this problem: I want to check the syntax of my php code. Therefore I use the command line function PHP -l, the structure is similar to the following code (example from the php Manual.) The Problem is: I read from the standard output with echo stream_get_contents($pipes[1]); this function is available only from PHP version 5, but I must write for version 4.3.0. Which way could it be solved? I don't want to use a temporary file. <?php $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to ); $cwd = '/tmp' $env = array('some_option' => 'aeiou'); $process = proc_open('php', $descriptorspec, $pipes, $cwd, $env); if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to /tmp/error-output.txt fwrite($pipes[0], '<?php print_r($_ENV); ?>'); fclose($pipes[0]); echo stream_get_contents($pipes[1]); fclose($pipes[1]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $return_value = proc_close($process); echo "command returned $return_value "; } ?>
View Replies !
PHP Execute Command Line Prog
Is there a cleaner way to execute a command line php script from within a web accessed php script? Im currently using exec("php foo.php"); but it seems like there should be a better way.
View Replies !
Running Script From The Command Line
I'm trying to set up email piping on my server and I'm getting the following error back in my email: /bin/sh: /var/www/vhosts/example.com/httpdocs/mailcontroller.php: /usr/bin/php : bad interpreter: No such file or directory I think the mail alias I set up in qmail is working correctly because when it wasn't I didn't get a script error back, just a user not found error. From the error it sounds like it's not able to find php but I've tested a script from the command line to that path and it works fine (php is running as CGI btw, rather than CLI). I'm guessing that it's making it all the way to mailcontroller.php because I don't have the /usr/bin/php path anywhere else but in that file. Could it be that it's actually running the script but can't get to stdin?
View Replies !
Connect To PEAR With Command Line
I have recently installed PEAR to my base directory next to my website which wasn't a problem (i hope). What i need to do now is install the BBCodeParser package. I need to know how to install this package using the command line. Do i use the command prompt on my PC and if so how do i connect to the web server which is on a host not stored locally.
View Replies !
|