I use php exec another php but this not working - php

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

Related

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.

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

execute remote php scripts using php.exe

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

Command line script in windows

I am trying to run a php script from the command line in windows using the following variations:
php script.php
php -f script.php
Both commands just print out the entire script but don't execute the script.
Sounds like you forgot to start the script with <?php.
Content in a PHP script outside of a <?php block goes direct to STDOUT.
Without contents of the script its difficult to see the issues.
Most likely is that you have not used <?php ?> tags or used the short hand. Try using the full <?php ?> tags.

Why Doesnt PHP Parse My Scripts?

I'm trying to get the php executable to parse scripts, but it's not working. i run something like this:
php c:\test.php
and test.php contains this:
<?
echo 'hello!';
?>
and that is exactly what running the command returns. It returns the raw code. How can I get it to actually parse the code and return "hello!" instead?
Make sure you have the short_open_tag setting enabled in your php.ini. Failing that, use the ever-so-slightly longer <?php to start your script.
Another option might be to try using the -f command line option.
php -f c:\test.php
It's been a while since I've ran php off the command line, but try this:
<?php
echo 'hello!';
?>
Also make sure that your webserver is correctly configured. If it is not configured to run .php pages through the php interpreter it may simply display as a text file.

Categories