I have a VPS Linux webserver with PHP installed.
I want to code some search engine or data mining stuff in one application which I am thinking of building in python.
I want to know if it is possible to use python and php together like calling functions of python in php and vice versa.
As it is my VPS server, I can install anything on that.
Has anyone tried using python in php? Are there any performance issues in real time??
You can execute python scripts using the exec() function in your php script.
Also this seems to provide an answer or two to your question.
Calling Python in PHP
You could have a look at PiP
To that end, I've [site author] written a Python extension for PHP. In short, this extensions allows the Python interpretter to be embedded inside of PHP (think of PHP as the parent language with Python as its child). This allows native Python objects to be instantiated and manipulated from within PHP. There is also initial support for accessing PHP functions and data from within the embedded Python environment.
However, I cannot comment on its reliability. Might need to test it for yourself.
You're trying to do something like
def helloWorld():
print 'Hello, World'
<?php helloWorld(); ?>
I'd say that you most certainly can't.
Edit: Have a look at php's shell_exec though.
I think that should be
<?php
$try = exec("/var/htdocs/folder/test.py")
?>
Try and see if it works
Better you have to do, use api, different application like one application on python server having python application and one server having php application with api. Like you store or delete data by using api in android or ios.
Related
My main app is written using PHP, but I'm using a Perl script to process a request, and I want to pass information to the PHP app using apache_notes. I would prefer not to use query parameters.
Here's the documentation on apache notes I found
for PHP
for Perl
On the PHP documentation, there is an example of how to use apache notes from PHP->Perl. Does anyone have an example of how to go from Perl->PHP, or suggest another way to securely communicate from Perl to PHP without having to go through query parameters?
You can use $r->subprocess_env("foo", $value), which from PHP will be visible as $_SERVER["REDIRECT_foo"].
Suppose I have a lot of math calculations which are quite tedious to implement in php. Is it possible to somehow link PHP and Octave on the server in such a way, that php sends parameters to Octave and receives answers back.
Has anyone tried anything similar?
Another solution is to use octave-daemon, which was written specifically for this purpose. Works on Linux, don't know about Windows.
You can use matlab compiler to make an executable matlab application, that you can call from php.
GNU Octave can be called from PHP using the Linux command line, using commands like exec() or passthru(). Anyway, their appropriate use depends on what you are trying to do (there are no details of your problem).
One way to do it, in Windows, is to compile Matlab as a DLL and include it ona web app (a WFC service, for example). At that point you have a functional "matlab service" and then you can access that service from PHP or any other language.
It is also possible to create a .NET component using Matlab Builder NE, and deploy it using SilverLight on the web.
How can I access my php script from a Python script?
I need my Python script to be able to access the variables within the php script. (By the way, I'm new to php and Python.)
Thanks in advance.
If I understand it correctly, you have a service in PHP, and want to communicate with another one in Python.
Now, this is not really related to PHP or Python: this is quite a classic issue of integration and there are several ways to accomplish it; without more details about your problem, it may be very difficult to be specific about a solution and what kind of approach could be the better for you, but below you can find some ideas.
You could for instance save the status from PHP service in an ad-hoc table in the database, and then query it from the Python service.
Another way could be to use a RESTful approach: the information is available as a resource, accessible via a GET query; in PHP you would have a small handler that would just return a small JSON (or XML, if you like that kind of stuff), and in Python you would have instead the client. Of course, there are security issues to consider, but I think you got the idea.
For more information, I recommend you having a look at an interesting series written some time ago by Paul Stovell about integration. It is very accessible, and shows several approaches - although not all of them apply to your current issue.
Elaborate. Is the PHP file local? On a webserver? Where's the python file?
If the php file is on a server with the python file, use an exec statement.
If the python file is local and the php file is on a server, then you need to use urllib.
If both are local, write an interpreter...
I need to call a dll that returns a string using PHP.
What would be the best possible way to achieve this?
Build a PHP extension that wraps the DLL or create a wrapper (in any language) that can be accessed via shell with exec.
This is not possible using native PHP.
I would look into running an operating system level function to do this using exec(), like for example rundll.exe (for some kinds of DLLs).
If rundll can't do it (it has something to do with managed and unmanaged DLLs, I don't know what that means), the easiest way may be writing a wrapper application that imports the DLL, performs the necessary actions, and outputs the result.
Is there any way to include php file using require and calling a php method in rails application ? I dont want to use phusion passenger as my server .
As far as I know, there is no PHP interpreters for Ruby, so your best bet would be to make an HTTP request from your Rails app to your PHP app to get its output. This of course won't allow you to directly call any specific function or such.
It might also be possible to run your Ruby application using JRuby, and at the same time, use Quercus. Quercus is a Java based PHP interpreter, so you might be able to interact through the JRuby Java interface with the Quercus parsed PHP script.
Disclaimer: Never used Ruby, JRuby or Quercus.
You could just run it through a shell command. There are several ways to do it, but here's one:
`php /path/to/your/script.php`
This will run the PHP script in the argument. If you care about the result of the script:
result = `php /path/to/your/script.php`
Disclaimer: I've never actually tried this so I don't know what it returns, but theoretically it should return whatever the script returns, if anything.