Currently I have a website on my local computer that uses PHP to make a call to a .jar program. It works fine when I run it on my local machine.
When I upload it to my host and try to run the same .jar file, I get no output...
Do you know why this is? Do I have to change the PHP.ini on my remote host to allow jars to be executable or something?
Any help is appreciated.
Thanks Phil
EDIT:
Code snippet:
shell_exec("java -jar news.jar get phil")
get and phil being two parameters to the news.jar program. I am using windows XP on my local machine, and I just have simple PHP MySQL hosting online. Does hosting such as this not support shell_exec() calls?
Code snippet: shell_exec("java -jar news.jar get phil")
It is extremely probable that this won't work out of the box on shared hosting, either because shell_exec() is disabled altogether, or executing java is not available to your shared hosting package, or the Java VM executing the jar doesn't have the rights to do what the jar wants to do.
You should be able to at least find out whether you can execute Java at all by using exec instead of shell_execute, giving it $output and &$return_var variables (see the linked manual page) and seeing what they contain after the call.
The best thing, though, would be talking to the provider and asking what is possible, and what isn't.
Related
I am using apache server under xampp. I have some matlab exe file that I want to execute. I used this template
$tmp = exec($command, $output, $return_var);
while $command contains the exact command to execute the file using cmd.
What is happening is the page hangs and when I debug, I found that the server hang while calling this exec command.
I searched the web and tried many things like run the Apache service and my user account and give the user all administrator privileges, but unfortunately it still stuck.
Any help or advice would be appreciated.
The problem with my code was because the Matlab code is accessing file system and also reads an excel sheet. So, it was all about permissions.
The solution for this problem has 2 parts:
1. Apache should run as a a windows service with checking allow service to interact with desktop in the properties.
2. I found that there is no way to access windows COM objects to read excel in normal way. So, instead we should use xlsread in basic mode.
That's all.
I'm very new to socket programming, but do lot of coding with php.
I have tested some socket server example codes and worked fine with localhost. I use CLI to run the server. But my concern is how do I run the socket server .php file at my hosting server? Do hosting providers normally give access to CLI to run the servers? How do I make sure my server is always running? If the hosting server is restarted, what happens to my server? In case, my server crashes (whatever reason), do I have to run it manually?
Can someone help?
If you are talking about a hosting server I expect you are talking about shared hosting. In that case it will be difficult to keep it stable if you even manage to run the service etc. I would suggests using at least a VPS for it. That way you can run it in the background, automatically start it at reboot but also install software to check the process and restart it if it failed.
For example: Testing whether the reboot startup works is impossible at shared hosting.
I don't know if your provider give you ssh access. Some provider do it but this are managed server or root server.
Then you can run your script over the CLI.
When you can run your server over CLI and when you have enough rights you can insert the script to the runlevel. And there is something that is called "shebang". With this you can give your script direct the php interpreter and run the script without the php command before.
php test.php or /usr/bin/php testScript.php
You can run direct run your script with test.php or name your script only testScript.
When you put your script to /usr/local/bin (for debian) you can run it everytime over the command like the php command.
Edit: I have forgotten something. For this solution you have to copy the /etc/init.d/skeleton to /etc/init.d/runPHPSocketServer for example and change the script values on top. Then you can insert it to the runlevel.
#: testScript or runPHPSocketServer start
When the script is under a executable directory you can insert it to your system runlevel.
#: update-rc.d runPHPSocketServer defaults
So you see there are some solution but for the most solutions you need ssh access.
Am using windows server for running website. My application is running in linux server. I want to call the application with parameters(inputs) from website using php. The application accepts some inputs and returns output. I want to display the output in website. Please some one help me by giving idea or scripts. Thanks in advance.
From your simplistic description, you might be able to use this on the windows webserver to invoke the application part residing on the linux server:
<?php
readfile("http://otherserver.com/app.php?input=123");
?>
If the inputs are expected via POST, then you'll have to utilize cURL instead. (Which you'd have to do in case of a disabled allow_url_fopen anyway.)
You can use WinExe in your Linux system and execute command from your PHP to remotely call command lines on your Windows system
First Note: Sorry this is long. Wanted to be thorough.
I really hate to ask a question when there's so much out there online but its been a week of searching and I have nothing to show for it. I'd really appreciate some help. I am a noob but I learn very fast and am more than willing to try alternate languages or whatever else it might take.
The goal:
What I'm trying to do is build a Netflix remote (personal use only) that controls Netflix on the server (Windows 7 PC 32-bit) via keyboard shortcuts (example: spacebar to pause) after a button is pressed in a php page on my ipod touch or android phone. Currently the remote uses USBUIRT to control the TV and IR devices without issue. If you have any alternate methods (that I can build, not buy) to suggest or other languages I could learn that can achieve this, I'm happy to learn.
The issue:
PHP's exec() and system() commands will not launch the python script (nor an exe compiled with py2exe) that simply presses the Windows key (intended to press the key on the server, not the machine loading the php page). I can use USBUIRT's UUTX.exe passing arguments with exec() to control IR devices without issue. But my exe, py, nor pyw files work. I've even tried calling a batch file that then launches the python script and that batch will not launch. The page refreshes and no errors are displayed.
Attempted:
Here's a code that works
$exec = exec("c:\\USBUIRT\\UUTX.exe -r3 -fC:\\USBUIRT\\Pronto.txt LED_Off", $results);
Here's a few attempts that don't work
$exec = exec("c:\\USBUIRT\\test.py", $results);
$exec = exec("python c:\\USBUIRT\\test.py", $results);
$exec = exec("C:\\python25\\python.exe c:\\USBUIRT\\test.py", $results);
All of those I've tried without the dual backslashes and with forward slashes and dual forward slashes. I've left off passing it to variable $exec and that makes no difference. $result outputs
Arraystring(9) "
Copying everything in the exec() into command line works correctly. I've tried moving the file to the htdocs folder, changed folder permissions, and made sure I'm not in safemode in php. Var_dump returns: Array" Using a foreach loop gives no info from the array.
My logs for Apache show only
[Sat Sep 10 19:54:09 2011] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/announce
Setup: Apache 2.2, python 2.5, and php 5.3. Running this on Windows 7 and only connect on the local network, no vpn or the like. Given every associated folder (python, htdocs, the cmd.exe file, usbuirt folder) IUSR, admins, users, and everyone with full control just for initial testing (later I'll of course tighten security up). Safe mode is off on php as well.
Notes: This code I saw on another similar issue doesn't work:
exec("ping google.com -n 1");
No errors in error.log nor event viewer. Putting it inside ob_start(); and getting the results with ob_get_clean(); gives me absolutely nothing. No text or anything at all. I've tried a lot more but I've already written a novel on here so I'll just have to answer the rest as we go. I'll post the full php source or the python script if that is needed but all it does is import sendkeys and press the windows key to pop open the start menu as a basic visual test. I don't know if its permissions, the way I have my setup running, my coding... I just don't know anymore. And again I apologize this is so long and if you do answer, I really appreciate you taking the time to read all this to help out a total stranger.
The PHP server running the script is most likely running as a different user (Network Service) than the account logged in at the GUI Console. I think this kind of setup might work under XP, and/or with the "interactive" field enabled on the service. However, I believe in Vista/7 it is blocked on security grounds. Details are a bit fuzzy as I'm now in front of a Linux box.
A solution would be to run php manually in the session that is running netflix and try again. If this doesn't work, I once wrote a simple client/server in python that takes key commands and converts them to keystrokes. Was pretty easy to do.
Figured it out thanks to the excellent help from Winston Ewert and Gringo Suave.
I set Apache's service to the Local System Account and gave it access to interact with the desktop. This should help if you have Windows XP or Server 2003, but Vista and newer there's an Interactive Services Detection that pops up when you try to launch GUI applications from php. Every command was executing correctly, but were doing so in Session 0. This is because Apache was installed as a service. For most people I would think that reinstalling without setting up Apache as a service would work, but I was considering moving to XAMPP anyway, so having to uninstall Apache helped push my decision.
Ultimately all of the codes I wrote in my original post now work as a result, and my project can move forward. I hope someone else stumbles across this and gets as much help from Winston Ewert and Gringo Suave as I did! Thank you both very much!
I have some PHP scripts that reside on a network share. For argument's sake, let's call the share \\nas\dev. I have a Web Site on \\w2k3dev\ set up in IIS6 that uses \\nas\dev\ as its home directory by setting "A share located on another computer".
Some of my scripts use shell_exec to execute functions on the server and return results to my script. Again for argument's sake let's say I'm just getting a directory listing like so:
echo shell_exec('dir');
If I run the script in IIS, I get no output - but no error logs either.
If I set up Apache on \\w2k3dev\ and configure it to use the same share, the script runs fine
If I copy the script to the local machine and run it through IIS it works fine.
So the problem only seems to be when IIS is set up to use a network share with a script containing shell_exec. Every other aspect of my scripts work fine.
Profiling in procmon, I can see that cmd.exe operates completely differently depending on whether it's being run by IIS or Apache. I have more details, but for the sake of being concise, I will omit them for now unless someone asks for more details.
Thank you so much for looking at this, I am at my wits end.
Kind regards
Iain
You may have a look at those IIS specific comments on php.net shell_exec's manual :
http://www.php.net/manual/en/function.shell-exec.php#84992
http://www.php.net/manual/en/function.shell-exec.php#70817
http://www.php.net/manual/en/function.shell-exec.php#70338
http://www.php.net/manual/en/function.shell-exec.php#43907