473,388 Members | 1,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

PHP Command Line called via exec();

Hi there

If I enter the following at the command line, I
successfully get an email sent to the correct name/email:
php /var/www/html/admin/adminscripts/welcome-cli.php
'Me' 'm*@me.net'
However, if I visit
"http://www.example.com/example.php?
vI*************@me.net"

which consists of the following:

<?php

@$vID = $_REQUEST['vID'];
@$vUser = $_REQUEST['vUser'];

exec('php /var/www/html/admin/adminscripts/welcome-
cli.php $vID $vUser');

?>

the email does not get sent.
I thought, "hmm, maybe $vID and $vUser are getting passed
as '$vID' and '$vUser' instead of 'Me' and 'm*@me.net' so
I tried: (please excuse the line breaks)

<?php

@$vID = $_REQUEST['vID'];
@$vUser = $_REQUEST['vUser'];

$vExecString = "php
/var/www/html/admin/adminscripts/welcome-cli.php $vID
$vUser";

exec('$vExecString');
?>
but still, the e-mail does not get sent. Does anyone
have any ideas/suggestions on how I can do this properly?
I've also tried system() and shell_exec() but to no
avail.

You might be asking why I am taking this route... the
answer is that the REAL script (the above is just a test)
will be sending 4,000+ emails, and I'd like to send the
website user to a new webpage immediately instead of
having stare at a blank browser window until the emails
get sent. Hence, my idea was to call the e-mail script
via the command line and send the user on their way to
view other pages while the mail gets sent in the
background.....

The system is a Linux box, Apache 2, PHP 5.0.2

I did not include any source from "welcome-cli.php"
because it is working properly via the command line
(telnet).

Thanks in advance....

Jul 17 '05 #1
8 6249
> <?php

@$vID = $_REQUEST['vID'];
@$vUser = $_REQUEST['vUser'];

$vExecString = "php
/var/www/html/admin/adminscripts/welcome-cli.php $vID
$vUser";

exec('$vExecString');
?>


The one thing I'd do is put

echo $_REQUEST['vID']; to see if the variable is actually there..

btw, what are the @ for?
Jul 17 '05 #2
Good Man wrote:
Hi there

If I enter the following at the command line, I
successfully get an email sent to the correct name/email:
php /var/www/html/admin/adminscripts/welcome-cli.php
'Me' 'm*@me.net'
However, if I visit
"http://www.example.com/example.php?
vI*************@me.net"

which consists of the following:

<?php

@$vID = $_REQUEST['vID'];
@$vUser = $_REQUEST['vUser'];

exec('php /var/www/html/admin/adminscripts/welcome-
cli.php $vID $vUser');


I ran into something like this when I first started with PHP. As a newbie,
I could not figure out if it was me or PHP, but it seemed that various
exec() and shell_exec() commands simply did not work. Nothing happened,
repeatedly. Ultimately I used back-tick, which worked, and I have never
gone back to figure it out.

So you can execute something like this:

$mycommand = "php /var/.../welcome-cli.php $Me $myemail";
`$mycommand`;

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #3
On 2005-05-06, Chris B <ze******@REMOVEzen.co.uk> wrote:
The one thing I'd do is put
echo $_REQUEST['vID']; to see if the variable is actually there..
I would use isset, array_key_exists, empty to test that.

And i would use
ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);

to make sure PHP warns me about eventual problems...
btw, what are the @ for?


http://www.php.net/manual/en/languag...rorcontrol.php
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #4
Kenneth Downs <kn**************@see.sigblock> wrote in
news:mp************@pluto.downsfam.net:
I ran into something like this when I first started with PHP. As a
newbie, I could not figure out if it was me or PHP, but it seemed that
various exec() and shell_exec() commands simply did not work. Nothing
happened, repeatedly. Ultimately I used back-tick, which worked, and
I have never gone back to figure it out.

So you can execute something like this:

$mycommand = "php /var/.../welcome-cli.php $Me $myemail";
`$mycommand`;


Wow.

Thanks for your post. In a million years I would not have tried that, and
of course, it worked!

THANKS!

Now I'm going to go off and investigate this back-tick business.....
Jul 17 '05 #5
Good Man wrote:
Kenneth Downs <kn**************@see.sigblock> wrote in
news:mp************@pluto.downsfam.net:
I ran into something like this when I first started with PHP. As a
newbie, I could not figure out if it was me or PHP, but it seemed that
various exec() and shell_exec() commands simply did not work. Nothing
happened, repeatedly. Ultimately I used back-tick, which worked, and
I have never gone back to figure it out.

So you can execute something like this:

$mycommand = "php /var/.../welcome-cli.php $Me $myemail";
`$mycommand`;


Wow.

Thanks for your post. In a million years I would not have tried that, and
of course, it worked!

THANKS!

Now I'm going to go off and investigate this back-tick business.....


Glad it helped!

If you come from a Windows background, you would never have heard of
backtick, it is a Unix thing that I learned when I moved to Linux about 4
years ago. You can put it into shell scripts, Perl, and PHP that i know
of, and probably many more.

Basically, the three quoting methods are:

Single Quotes are completely literal, so:

$variable = 'something';
$myvar = 'This $variable will not be substituted\n';

will actually contain the string '$variable' instead of the substituted
value 'something'. It will also contain a slash followed by an n, the
string '\n', instead of a newline character.

Double quotes will evaluate variables and control characters, so:

$myvar = "This $variable will not be substituted\n";

will put "This something will...." into $myvar, with a newline at the end.

Backtick is fascinating because it means *execute* the string and return the
results. It will also accept interpolation (at least in Bash it does, I'm
kind of assuming it does in PHP), so you can do this:

$somedir = "/home/ken/letters/";
$myfiles = `ls $somedir`;

and now $myfiles contains a directory listing. Supercool.
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #6
hi,

just saw this post while killing time. if you would want to pass
arguments to your php scripts you can use this:

exec("/path/to/php -f your_file_name.php $argument1 $argument2");

and when your_file_name.php is executed the arguments are available in
the $argv array which is filled with the arguments you gave to the
file.

so you can make another file say 'example.php' and pass it arguments in
query string like this
ex***********************************@somewhere.co m

and use the $_GET array to pass the values to the exec command.

Hope this helps

Jul 17 '05 #7
Just to add on to this,
just saw this post while killing time. if you would want to pass
arguments to your php scripts you can use this:

exec("/path/to/php -f your_file_name.php $argument1 $argument2");

and when your_file_name.php is executed the arguments are available in
the $argv array which is filled with the arguments you gave to the
file.

so you can make another file say 'example.php' and pass it arguments in
query string like this
ex***********************************@somewhere.co m

and use the $_GET array to pass the values to the exec command.


Do not pas the arguments straight in there without using escapeshellarg
for arguments and commands with escapeshellcmd :)

Mike
Jul 17 '05 #8
I ran into something like this when I first started with PHP. As a newbie,
I could not figure out if it was me or PHP, but it seemed that various
exec() and shell_exec() commands simply did not work. Nothing happened,
repeatedly. Ultimately I used back-tick, which worked, and I have never
gone back to figure it out.

So you can execute something like this:

$mycommand = "php /var/.../welcome-cli.php $Me $myemail";
`$mycommand`;

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
For some reason when doing a shell_exec, you can't pass php variables. The following will not pass the variables $Me and $myemail:
shell_exec('php /var/.../welcome-cli.php $Me $myemail');

whereas this will :
`php /var/.../welcome-cli.php $Me $myemail`;

I prefer to use shell_exec than the backticks as it makes code more readable. The following is your example, using shell_exec:
$mycommand = "php /var/.../welcome-cli.php $Me $myemail";
shell_exec($mycommand);

As you can see it is almost exactly the same. These problems can be diagnosed when using a colourful editor (one that interprets the code and assigns text different colours based on how the code is interpreted).

astro_dave.
Jun 6 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andreas Paasch | last post by:
According to the manual for PHP, I should be able to run a shell command within php. I'm trying to copy some php files from one location to another one using exec() but fail. ...
9
by: Manlio Perillo | last post by:
Regards. In the standard library there are two modules for command line parsing: optparse and getopt. In the Python Cookbook there is another simple method for parsing, using a docstring. ...
0
by: andrea valle | last post by:
Hi to all, I need to run a program from inside python (substantially, algorithmic batch processing). I'm on mac osx 10.3.8 with python 2.3 framework and macpython. Trying to use exec*, I...
1
by: ktsirig | last post by:
Hi all, I need to execute a command-line program through PHP. I have a form which includes a textarea, where the user writes his data. These data will be used as input for the command-line...
17
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php"...
1
by: Manish | last post by:
I have the following code in a script -------------------------------------------------------------------------------------------------------------------------------- foreach($serverlist as...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
2
by: Taras_96 | last post by:
Hi everyone, I'm trying to run a number of commands stored within a sql file from within php using mysqli::query. The syntax I'm using is: source C:\data\projects\forum...
7
by: swethak | last post by:
Hi, i have a command to convert the video file into image ffmpeg -i sample.wmv -f image2 -t 0.001 -ss 3 ss.jpg i run that one in command prompt it converted the video file into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.