how to have R opencpu interact with php - php

I am new to php and have some experience with R opencpu.
Suppose I use localhost (127.0.0.1) to host my opencpu with the (default) port of 8004. Then, I cannot run the Apache using the same port. Instead, I have to run it in another port, say 8080. Then all my .php will be held on a server of the port 8080.
So how can I connect my .php files when running a opencpu app?
I thought that I could put my .php files in inst/www, where my index.html is. However, when I do so and open the page of http://localhost/ocpu/library/.../www/xxx.php, my browser automatically downloads the .php file but not executing it.

You'll need to ensure your web server is configured to properly serve PHP, which is a whole other thing. However, if you're only accessing files on localhost then you can just execute the PHP files directly using the system2() command.
output <- system2('php', c('/path/to/script.php', 'arg1', 'arg2'), stdout=TRUE)
Setting stdout=TRUE ensures the output from the script is returned for later use.

Related

.php downloads instead of opening in Chrome and FF

I'm using sftp to reach my folder on a server at uni. Both chrome and firefox would download my simple test.php instead of opening the page.
Is there any suggestion where should I look with the preferences to change this? (Ubuntu 16.04)
Oh, okay I understand it now, my bad.
I literally mounted the server to my local machine with ssh, thus I had no server whatsoever.
I had to reach directly with the url to open it, so I couldn't just open it from editor (VS Code - open with browser).
Your webserver isnt passing the php file to php for processing and is just sending it on as it would any other file. You will need to ensure that your webserver is setup to handle php correctly be it php-fpm for apache and nginx or the php module for apache
What's the webserver? You can start to read here: http://php.net/manual/en/install.php

Get file from distant PC

I have a PC connected to a Raspberry via an Ethernet network. In Raspberry there is the file Stb.php in directory /var/www/ the IP of Raspberry is 192.168.1.15.
I like to use a function in file Stb.php named sendScreenCommand from my server which installed in my PC.
Here is my code but it is not working:
include 'http://192.168.1.15/Stb.php';
$command="mkdir /flash/Resources/resources"
sendScreenCommand($command);
You can enable allow_url_include in your php.ini configuration file.
Doing this is strongly discouraged, as it can present serious security risks.
You cannot do it like that. The path you are using is a url on a web-server and according to the manual:
This is not strictly speaking the same thing as including the file and
having it inherit the parent file's variable scope; the script is
actually being run on the remote server and the result is then being
included into the local script.
So your php file is being parsed / executed on the Raspberry and all you get back are the results so there are not functions to execute.
Unless Stb.php outputs php code of course, but that seems very unlikely from what I understand from the question...
If this is on a local network, you could make it work if you can mount the file-system of the Raspberry on your pc so that you can use a file path like for example:
include '/mnt/Raspberry/Stb.php';
(assuming something like linux or OSX, on Windows it would be a bit different)

A way to remotely run my PHP file

I have created a .php file, which I can run from my Mac and it works great.
This .php file needs an SSL connection,and it also has another file it uses (certificates .mem for APNS) .
I would like to be able to remotely run this file from any browser, in my Mac, so i will get some IP address, that when opened in a browser, the .php will be executed.
I was trying port forwarding, without any success, and I am looking for other services that do that.

instead of opening php, browser downloads php in Ubuntu

I installed php and apache2 correctly, I am able to open localhost/index.php. Index.php is located in /var/www.
However when I open port 8000 by python -m SimpleHTTPServer 8000, localhost:8000/index.php will not be opened, the browser will just to start to download it.
I also add Listen 8000 in ports.conf.
What else do I need to change to make it work properly?
One more question, what do I need to change make php work in all files not just /var/www?
Thanks
You're using python to respond to the HTTP request, not Apache, so Apache never gets a chance to execute index.php.
Try Google to learn how Apache works.
I just solve my problem. I edited apache2.conf and add 8000 port, then I change the document root to my home directory.

how to give command line to run browser which in turn runs php script

question is how to give command line (in .cmd script) to execute browser to then in turn have browser execute .php script.
Presently if from a command window I execute like ...
"c:\Program Files\Internet Explorer\iexplore.exe" file:\c:\users\win7ultsdtest\findroot.php
....OR....
C:\Program Files\Internet Explorer\iexplore c:\users\win7ultsdtest\findroot.php
This will run the Explorer browser, but then the browser the browser will download the contents of findroot.php instead of executing the php code as I need. Does anyone know how I can get the browser to instead execute the php code and not just download it as data?
Let me explain my need ... The findroot.php file contains php code to access the $_SERVER['DOCUMENT_ROOT'] variable. This variable is ONLY non-null when the localhost is running a http server and then it contains the localhost document server root path where loadable browser .html, .php etc may be stored to loaded from http:\ lines.
The findroot.php outputs the $_SERVER['DOCUMENT_ROOT'] contents to a file as rootpath.txt so that my .cmd script can then can automatically install PHP code into the active PHP servers document root area.
So understand I must find the $_SERVER['DOCUMENT_ROOT'] from a .cmd script.
Now I might search ALL the computers drives for httpd.conf and then scan that file for the value but this wouldn't work for two reasons; 1. there can be multiple httpd.conf files and I can't know which server is active and using what httpd.conf. 2. it would take a long time to search a given computers entire drive(s) on all httpd.conf files.
The browser won't execute PHP code. You either need a server to run PHP and to access it via HTTP such as C:\Program Files\Internet Explorer\iexplore http://localhost/url/for/findroot.php or you can run PHP via the command line c:\path\to\php.exe c:\users\win7ultsdtest\findroot.php. However running it via the command line won't give you $_SERVER['DOCUMENT_ROOT'] as that is only populated when running PHP within a server.
It's not possible to execute PHP by the HTTP server without the server knowing about the PHP before hand - for example, by being in the document root. Of course if you don't know the document root, your script won't be there. If you're trying to install a script into a web server for a user, it's much better to give instructions on how to do so as their server environment will likely vary from what you expect.
There are light browsers like lynx if you are in a linux machine
lynx http://whateverurl/php.php

Categories