-1

I've create a script that execute some part from the php script by calling the 'request' GET,

Is there a way to execute the script via SHELL like this : php -q script.php?request

I've executed but nothing is happening.

Any help is appreciated

Dario
  • 704
  • 2
  • 21
  • 40

1 Answers1

2

you would typically place the arguments after the command:

php -q script.php request arg2

inside the file it would be read with

$request = $argv[1];
$arg2 = $argv[2];

($argv[0];) is the script name

Edit

from the command line:

php -q script.php request

and inside script.php:

 $request = $argv[1];
if(isset($request){
 echo 'run this part';
}

Edit2

I suppose if the arguments are conditional you could do something like:

php -q script.php 'arg1:foo-arg2:bar'

and

$request = $argv[1];
$parts=explode('-',$request);
$args=array();
foreach($parts as $part){   
   $arg=explode(':',$part);
   $args[$arg[0]]=$arg[1];
}

that would give you :

array(
    arg1 => 'foo', 
    arg2 => 'bar'
      )
andrew
  • 9,313
  • 7
  • 30
  • 61
  • I really cannot catch this, is a bit unclear for me, lets say that i have this: if(isset($_GET['request'])){echo 'run this part';} – Dario Jul 09 '14 at 21:06
  • i understand, the issue is that if i type a second $_GET['request2'] it execute request – Dario Jul 09 '14 at 21:17
  • yup ok that would be `php -q script.php request request2` and `$request2 = $argv[2];` etc – andrew Jul 09 '14 at 21:22
  • i got undefinied offset instead the execution of script, but even if i type scrip.php argument1 argument2 argument3 the part of script that execute is argument1 and work only with 1 offest on add the second it return undefinied offset – Dario Jul 09 '14 at 21:26
  • in any case, i solve the issue switching the PHP -q with GET – Dario Jul 09 '14 at 21:32
  • ok see the above edit – andrew Jul 09 '14 at 21:38