Hi, I need to run a PHP file from another PHP file automaticly in the server. Is it possible to do that? Usually we run PHP by using browser right? What I need here is to run a PHP file without being view or invoked from the browser. Much like calling a function, but now I am calling a PHP file to run hiddenly by using another control PHP file. Is it possible to do like that?
PHP running PHP
What SAPI do you have?
If you don't know type php -v and it will tell you whether php is CGI or CLI.
If it's CLI, then there are many possibilities to accomplish your task.Telling PHP to execute a certain file.
php my_script.php
php -f my_script.php
Also you can use the "passthru function"
Check for more details:
http://www.php.net/passthru
If you don't know type php -v and it will tell you whether php is CGI or CLI.
If it's CLI, then there are many possibilities to accomplish your task.Telling PHP to execute a certain file.
php my_script.php
php -f my_script.php
Also you can use the "passthru function"
Check for more details:
http://www.php.net/passthru
Could you try to explain that more thoroughly?
Do you just want to include a php file without having it to output anything?
Do you just want to include a php file without having it to output anything?
| Code: |
| ob_start();
include('your_file.php'); ob_end_clean |
That'll include a file and throw away all output.
| rvec wrote: | ||
That'll include a file and throw away all output. |
that is what I was about to suggest....
it can even be called using @include() which will hide the error if it happens (file missing or other errors)...
I have an PHP script which is a application that will create, modifiy an output file. I need it to be invoked from another PHP script/HTML script which can be browsed by user. The hidden "application PHP" is running in the server without showing to the user. Can it be done like that? I think php:passthru is what I need, I will have a try on it and see. Any other suggestion is welcome. Thanks a lot!
| eudbase wrote: |
| I have an PHP script which is a application that will create, modifiy an output file. I need it to be invoked from another PHP script/HTML script which can be browsed by user. The hidden "application PHP" is running in the server without showing to the user. Can it be done like that? I think php:passthru is what I need, I will have a try on it and see. Any other suggestion is welcome. Thanks a lot! |
| eudbase wrote: |
| ... What I need here is to run a PHP file without being view or invoked from the browser. Much like calling a function, but now I am calling a PHP file to run hiddenly by using another control PHP file.... |
Well, include seems to be the logical answer BUT IT'S NOT. He needs something automatic and hidden, more like a batch background process.
why would he need that?
The best way to do that would be include.
The other way would be to run it like you said before with exec('php -f file.php'), but it'd do just the same.
| Quote: |
| I need to run a PHP file from another PHP file automaticly |
The best way to do that would be include.
The other way would be to run it like you said before with exec('php -f file.php'), but it'd do just the same.
| Quote: |
| He needs something automatic and hidden, more like a batch background process. |
How I know php scripts are hidden and run on the server. No one can see the code or process and only results are printed out. If he don't want to allow anyone to run php directly in browser (and only allow include), this is absolutely different question. In that case he need to check PHP_SELF.
Sonam
Related topics
