PHP script doesnt execute after set_time_limit(0) - php

I've got set_time_limit(0) added on one of my PHP scripts where I want the script to call an API to fetch details, which is slow.
But the PHP script wont execute after the set_time_limit(0) on my PHP installation.
To give some more information.
If I have this script
<?php
echo "Hello I am here<br>";
set_time_limit(1);
echo "Hello I am still here<br>";
It Returns
Hello I am here
Hello I am still here
If I have this
<?php
echo "Hello I am here<br>";
set_time_limit(0);
echo "Hello I am still here<br>";
It doesn't return anything but the browser keeps spinning.
I've got OSX sierra, and PHP 5.6 any help to debug would this will be great.

I found an answer, but not sure why this was happening.
I had PHP installed via brew, and a bundled version from http://php-osx.liip.ch/ was installed.
That was creating issues with the set_time_limit function. However when I switch back, and make php using the binaries the issue seem to be gone.
Still not sure whats happening in the first please.

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.

Unable to run Windows net.exe in php system()

I have PHP v5.3.28 setup up in Internet Information Server on WIndows Server 2008. I need to run a NET VIEW command from within my index.php file and display the output. I have not found any way to make this happen. I have been trying with system(), exec(), putting it into a .cmd file and executing that using code similar to that shown below. Nothing comes out, nothing returned. I can run other simple commands such as an xcopy, but using NET.exe does not seem to work at all.
echo "<pre>";
$str=system('C:\Windows\system32\NET1.exe VIEW \\tpptra01',$rtn);
$str=system('D:\tmp\tpptra01\cpdbfiles.bat',$rtn);
$str=exec('C:\Windows\system32\NET1.exe VIEW \\tpptra01');
echo "</pre>";
Any suggestions would be greatly appreciated, I'm at a loss.
Try this,
echo "<pre>";
echo shell_exec("C:\Windows\system32\NET1.exe VIEW \\tpptra01");
echo shell_exec("D:\tmp\tpptra01\cpdbfiles.bat");
echo shell_exec("C:\Windows\system32\NET1.exe VIEW \\tpptra01");
echo "</pre>";

php on nginx stops executing php code

I recently set up nginx and php. PHP is running and executes index.php just fine. It will output echo "hello world!"; just fine.
However after that, I'm including several PHP files and once this happens, it starts displaying the PHP code in the browser -- not executing the code.
What can I do to troubleshoot this? Any ideas?
There was someone on serverfault with a problem i think is similar to yours, maybe worth checking: https://serverfault.com/questions/247093/getting-php-to-work-with-nginx

How to execute a batch script from PHP

Server Specs
Windows 2008Rc2
IIS7
mysql
PHP 5.3
I have a batch file that does a mysql dump and then zips up the contents and makes it available for download in a public folder. Now i know this scripts works because it runs fine every-time i run it manually, but i can't seem to get it to work through php.
Basically I would like to just be able to call a php page that will run this batch file.
I know that exec is enabled as im able to use shell_exec to ping google.com, and i can get the output back.
I've tried with just system() and exec(), but still nothing. In some cases it looks like the page is working, but it just sits on the loading prompt.
I've searched high and low trying a million different combinations of commands, but none of them seem to work for me.
I've been reduce to trying this simple command, as i can get ping to work from this. Although when the page is called it only displays the echo statements.
<?php
echo "Starting...";
echo shell_exec("C:\inetpub\wwwroot\DBZIP2");
echo "Success!";
?>
I've also tried this, but the page just hangs on a loading screen and doesn't display the echo commands.
<?php
echo "Starting...<br><br>";
system("cmd /c START C:\inetpub\wwwroot\DBZIP2");
echo "Success!";
?>
Not really sure where to go from here. I've tried pathing the cmd.exe file, but that made no difference. Is there an easier way to do this? Another programming Language perhaps? Any help is appreciated.
Try executing using "shell_exec" with a full path to CMD.exe
<?php
echo "Starting...<br><br>";
shell_exec("c:\WINDOWS\system32\cmd.exe /c START C:\inetpub\wwwroot\DBZIP2");
echo "Success!";
?>

Call osascript through php shell_exec doesn't work

I was trying some things with osascript when I had this problem.
Here is my test :
/usr/bin/osascript <<-EOF
tell application "System Events"
activate
display dialog "Hello world"
end tell
EOF
Here is my PHP file.
<?php
$output = shell_exec("./test");
echo "<pre>$output</pre>";
?>
Do you have any ideas why this does not work? (It's not really important but I was just curious about it)
I suspect the osascript executable requires environment variables to be set up to work correctly, which is why this works fine from the console. See this answer to show you how to set these up from PHP.
In my case it was the HOME variable, but it could be something else. Keep adding them until it works!

Categories