execute remote php scripts using php.exe - php

Im executing a PHP script using php.exe command.
All the script executes well, but under certain condition (using if condition) I must call a second one in a remote server.
I tried adding this line "header('Location:http:// XXX .php');" that works well if I use iexplorer, but this line do not works if I use CLI "php.exe".
Anyone knows how can I call a remote script using PHP.EXE command?
Thanks in advance.

Maybe you are thinking about this:
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
http://php.net/manual/en/function.file-get-contents.php

Related

I use php exec another php but this not working

i have this file:
pippo.php
exec(ExportExcel.php);
ExportExcel.php
#!/usr/local/bin/php
<?php
$stop=1;
......
php code
......
?>
The exec command runs the file but I don't know what it is doing. It remains hung up and I don't get to activate the breakpoint placed in the file.
Any idea?
Thnak's
You need to pass a string to exec(), so maybe try exec('./ExportExcel.php');
Reference: https://www.php.net/manual/en/function.exec.php

Issues with exec() on php running a shell script

I'm trying to use a php script for executing a shell script. However I'm having some issues apparently with the web server.
I have a bash script called switch_audio.sh. It basically changes the active audio output of the system.
I also have a script.php that runs the code below:
<?php
echo "It's working";
exec("/var/www/html/switch_audio.sh");
?>
When I execute php script.php it's working fine. However, when I try to run it on the web browser by localhost/script.php I just get as ouput the "echo" part.
I've already tried to:
remove 'exec()' from the disable functions in php.ini;
give permissions for everybody in every folder on this path from "/" to the localhost folder;
Any thoughts about it?
Simple solution: exec() returns a string, but you also have to output it to the user:
<?php
echo "It's working";
echo exec("/var/www/html/switch_audio.sh");
?>
You already said you allowed the shell function on your php.ini configuration but it seems it's not working yet... so maybe:
You didn't restarted webserver service after changes
You have somewhere other statement more restrictive... maybe ini_set in your php files.
As a reminder, be sure that you are doing well on your php.ini file, check it for this kind of statement:
disable_functions=exec,passthru,shell_exec
Maybe you can try instead of exec other similar php function like shell_exec to check if it works. Or maybe is working and not showing anything.

Echo exec not working tesseract

I'm working on using tesseract with PHP and this is my first time using such things as exec.
/usr/local/bin/tesseract /images/hello.png stdout works perfectly via SSH but nothing happens when I try and run this via PHP;
echo exec('/usr/local/bin/tesseract images/hello.png result');
But if I try;
echo exec('/usr/local/bin/tesseract images/hello.png result 2>&1');
Then the page writes Tesseract Open Source OCR Engine v3.03 with Leptonica So I feel like I must close.
Any ideas?
Got it working using the following
exec('/usr/local/bin/tesseract /images/hello.png stdout', $msg);
print_r($msg);
http://php.net/manual/en/function.exec.php
Return Values
The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.
To get the output of the executed command, be sure to set and use the output parameter.

Find out what PHP is running on

I have a script which is running on Apache and also can be executed from command line.
How can i know, on what is php script running, apache or command line?
There is a constant build in PHP that you can use PHP_SAPI. If you are on the commandline the value of this constant is cli than you are on the command line. Every other value like cgi, cgi-fcgi, etc.
Why not add a parameter and only pass it when invoking from the command line?
http://php.net/manual/de/reserved.variables.argv.php
Create a page upload it and browse to it.
See page contents below.
<?php phpinfo(); ?>

How to run a php file from bash script?

I am working in a Windows machine. I need to run a script that will execute a php file. When I run where php to find my php executable location I get the following:
c:\xampp\php\phpe.exe
After that I tried something like this:
#!/bin/bash
#!/c:/xampp/php c:/xampp/htdocs/Bash/testingphp.php
I don't get any error, but I don't know if the script is doing something. Just for reference I am using cygwing to run the scripts. How do I know if my script is really working??
Thank you in advanced
As stated by #Etan, your second line is a comment, but your paths are also incorrect. You need to use /cygdrive/c/, not /c:/. Here is the corrected script:
#!/bin/bash
/cygdrive/c/xampp/php /cygdrive/c/xampp/htdocs/Bash/testingphp.php

Categories