0

I've been told (from a previous question of mine) that to run an external PHP script, i could use exec or curl.

I've started looking into exec and it seems simple, however I believe I am doing something incorrectly.

Is this not the correct, simple way to just run a page (and not require any data returned)?

exec("/folder/some_page.php?var=" . defined_variable);

I've tried different combinations of relative and direct links, with/without starting with a slash.

Thanks everyone!

9
  • 1
    If it's on your server - why not use include? "that to run an external PHP script, i could use exec or curl." --- I'm sure you get it wrong. Commented Nov 26, 2012 at 1:33
  • I don't want any of the data/output that is on that page. just want it to run on the server and no more. If I use include, then the resulting data is included on my page, which is no bueno. Commented Nov 26, 2012 at 1:34
  • to get the best answer in your case - you need to provide more details of what you're trying to do. meta.stackexchange.com/questions/66377/what-is-the-xy-problem Commented Nov 26, 2012 at 1:35
  • 1
    you haven't explained why include is wrong. The thing is - newbies often follow the wrong idea thus ask about wrong solutions. Commented Nov 26, 2012 at 1:37
  • 1
    if you don't want it to output anything - just capture it with ob_* functions Commented Nov 26, 2012 at 1:42

2 Answers 2

2

exec() runs a program, not a script. In your case, you'd need to call the php executable and pass it the path to the folder on the server. You'd also have to use the command line syntax for passing query parameters, not the URL syntax.

See here for more details on command-line PHP usage (which is what exec() is essentially doing, minus the interactive component): http://php.net/manual/en/features.commandline.php

Sign up to request clarification or add additional context in comments.

Comments

2

Execute the php:

exec("/folder/some_page.php $var1 $var2 $var3 $varn");

Get the variables in some_page.php:

$var1=$argv[1];
$var2=$argv[2];
$var3=$argv[3];
$var4=$argv[n];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.