I have a website built with PHP.
I have an Erlang application running as a daemon on the same server.
I need to call functions on the Erlang application from PHP and get back the result.
I've found PHP/Erlang and over PHP modules but I can't install a PHP module on this server, I can only use PHP code.
The only way I know to solve it is run an Erlang web server locally that the PHP will be able to talk to.
Is there a better way to solve it?
If using a httpd server is the best way, what Erlang server should I use?
It should be as light as possible and doesn't need features like SSL and doesn't need to handle large load.
Thanks
I'd run a webserver such as mochiweb hosting the erlang code. The PHP code would use curl to send http queries encoded in JSON to mochiweb. Mochiweb has a JSON encoder/decoder and PHP has native JSON support.
Even if every thing is on the same server, just use HTTP. Handles all the low level stuff and if you need to scale, it will be easier, as scaling with HTTP is a solved problem. Mochiweb is light and has high performance.
Erlang is excellent at socket I/O: maybe you could use a pipe of some sort?
This would be more direct than through another WEB server layer for sure.
Use the functions erlang:open_port and erlang:port_command functions to get data in/out of Erlang through a system port.
$ cat erl.erl
#!/usr/bin/env escript
main(Args) ->
io:format("~p\n", [Args]),
io:format("~p\n", [(catch test(Args))]).
test([N1,N2|_]) ->
lists:seq(list_to_integer(N1),list_to_integer(N2)).
$ chmod +x erl.erl
$ cat php.php
?php
var_dump(exec("./erl.erl 1 5"));
?>
$ php php.php
string(11) "[1,2,3,4,5]"
Have a look at erl_call. http://www.erlang.org/doc/man/erl_call.html
It is a unix program which is used to call a function in erlang. It will start a dummy erl node, execute the command(s) and return the result. You could use PHP to call erl_call and then use the results it returns.
I don't think there is better solution.
I need Erlang webserver to run it on web.
here is some info PHP+Erlang related
http://yaws.hyber.org/cgi.yaws
Related
I'm trying to make sense on the best way to do automatize a series of things in a row in order to deploy a web-app and haven't yet came up with a suitable solution. I would like to:
use google's compiler.jar to minify my JS
use yahoo's yui-compressor.jar to minify my CSS
access a file and change a string so that header files like "global.css?v=21" get served the correct version
deploy the app (sftp, mercurial or rsync?) omitting certain directories like "/userfiles"
Can you guys put me on the right track to solve this?
Thank you!
you may want to check out phing http://phing.info/ (they are in the process of moving servers so may be down this weekend), but it can do all of what you are wanting and is written in php.
A quick google search should bring up plenty of tutorials to get you started.
You can run php from the command line to do all sorts of fun things.
$ php script_name.php arg1 arg2
See: command line, argv, argc, exec
Running PHP from the command line is very fast. I've been doing this a lot lately for various automation tasks.
I generally run Python projects so this may or may not be an option for you: but apart from writing your own scripts you could look into the following:
Fabric
Buildout
maven
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.
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.
I'm trying to make sense on the best way to do automatize a series of things in a row in order to deploy a web-app and haven't yet came up with a suitable solution. I would like to:
use google's compiler.jar to minify my JS
use yahoo's yui-compressor.jar to minify my CSS
access a file and change a string so that header files like "global.css?v=21" get served the correct version
deploy the app (sftp, mercurial or rsync?) omitting certain directories like "/userfiles"
Can you guys put me on the right track to solve this?
Thank you!
you may want to check out phing http://phing.info/ (they are in the process of moving servers so may be down this weekend), but it can do all of what you are wanting and is written in php.
A quick google search should bring up plenty of tutorials to get you started.
You can run php from the command line to do all sorts of fun things.
$ php script_name.php arg1 arg2
See: command line, argv, argc, exec
Running PHP from the command line is very fast. I've been doing this a lot lately for various automation tasks.
I generally run Python projects so this may or may not be an option for you: but apart from writing your own scripts you could look into the following:
Fabric
Buildout
maven
I am writing a small web server, nothing fancy, I basically just want to be able to show some files. I would like to use PHP though, and im wondering if just putting the php code inside of the html will be fine, or if I need to actually use some type of PHP library?
http://www.adp-gmbh.ch/win/misc/webserver.html
I just downloaded that and I am going to use that to work off of. Basically I am writing a serverside game plugin that will allow game server owners to access a web control panel for their server. Some features would be possible with PHP so this is my goal. Any help would be appreciated, thanks!
The PHP won't serve itself. What happens in a web server like Apache is before the PHP is served to the user it is passed through a PHP parser. That PHP parser reads, understands and executes anything between (or even ) tags depending on configuration. The resultant output, usually still HTML, is served by the web server.
There are a number of ways to achieve this. Modules to process PHP have been written by Apache but you do not have to use these. PHP.exe on windows, installed from windows.php.net, will do this for you. Given a PHP file as an argument it will parse the PHP and spit the result back out on the standard output.
So, one option for you is to start PHP.exe from within your web server with a re-directed standard output to your program, and serve the result.
How to create a child process with re-directed IO: http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx however, you won't be writing the child process, that'll be PHP.exe
Caveat: I am not sure from a security / in production use perspective if this is the most secure approach, but it would work.
PHP needs to be processed by the PHP runtime. I'm assuming the case you're talking about is that you have a C++ server answering HTTP queries, and you want to write PHP code out with the HTML when you respond to clients.
I'm not aware of any general-purpose PHP library. The most straightforward solution is probably to use PHP as a CGI program.
Here's a link that might be useful for that: http://osdir.com/ml/php-general/2009-06/msg00473.html
This method is nice because you don't need to write the HTML+PHP out to a file first; you can stream it to PHP.
You need execute the PHP page to serve the page it generates.
The easiest thing for you to do would be to add CGI support to your webserver in some basic form. This is non-trivial, but not too difficult. Basically you need to pass PHP an environment and input, and retrieve the output.
Once you have CGI support you can just use any executable, including PHP, to generate webpages.