I'm on a road to build a PHP extension module to allow PHP to communicate with the R programming language.
My objective for this module is to allow me to run some R function directly from PHP.
I haven't build any extension on PHP before, but I know how to write a php program. I know a little bit about C and C++
I'm interested to hear what the expert advice on this one.
Here's some of the questions I want to know:
Is it possible to achieve the above idea?
What tools do I need?
What is the effective way to do this?
Please use the search feature at the top-right before you post.
Similar questions have been asked before, see e.g.
Pass and get variables between PHP and R
Integration of R Language with php to take the result from R
php and R integration
and there are probably more.
Related
There's a PHP library that I'm really interested in using. However, there's no R implementation of it nor do I see an interpreter between the two. I've searched on Google but it seems like most implementations are either displaying R plots or figures on a webpage via PHP or passing command-line arguments to each script. R blogger article about PHP and R seemed to be geared towards building a web application.
I've seen reticulate package achieve similar this within Python, but I was hoping we have something like this for PHP.
I've thought of a method of passing it through via exec(paste0('php ', <script>), but I don't think that's the best direction to take.
Are there better ways to implement this?
I am learning to build a web application based on graph theory(Linked-In) kinda thing. So as I thought of considering PHP for getting the inputs from user via web page and using C for internal programming like adding,deleting vertex, edge to/from the graph with the help of C structures and various algorithms. So I need to know how to use C code to drive my functions while I use ASP or PHP for handling webpage.
I wish to use C preferably.
Using Xampp 1.7.4 on Windows7
Actually it shouldn't be that hard to code...
If you already learned C, Then I suggest you to start learning sockets.
You didn't specify the OS, So here's links to a great tutorials both
Linux
&
Windows.
Now, if you don't want to use sockets, I suggest you to take a look at "Apache - Thrift".
You can communicate between functions in PHP and functions in C.
Example -
$shutdown->Shutdown();
Or
$points = (int*)points;
Good luck.
I'm a 5 years Python programmer, but shortly I'll be also working with PHP. Could you recommend me some readings to getting in touch with this language having in mind my Python skills?
This table has a list of many cognate expressions in php, python, ruby and perl.
Ask HN: PHP for Python Programmers
If you are familiar with MVC start learning from Zend Framework I think it will be easier for you to understand php, right php developing this way with a right leg start.
Object oriented business logics are same in any language.
I really want to get into python so we can exchange knowledge ;)
the best resource IMHO is still php.net there are a ton of decent books out there, but I still prefer to rely on php.net for the latest and greatest.
My PHP app has a number-crunching part that is just to slow for PHP, so I was thinking of building a custom C extension, but it is impossible to find any good reference to start with :(
Is there a guide on how to do something like this?
The best resource, although outdated in several aspects (it only covers PHP until version 5.1) is Extending and Embedding PHP by Sara Golemon. Even more outdated is the PHP documentation. On the other hand, the content on the PHP wiki is very up-to-date, but also quite incomplete and not very oriented for beginners. See also these articles, part V of Advanced PHP Programming by George Schlossnagle, chapter 14 of Programming PHP by Rasmus Lerdorf and Kevin Tatroe and, specially, these slides.
Finally, the most authoritative source you'll find is the source code of the extensions bundled with PHP.
This might not be an answer but more like a suggestion, There are tools out there to compile your php to an executable, which you could just then use as an extension. This Would uniform your code a bit and unify your project. I have tried something like this a while ago. The compiled php acts no differently than the compiled c would.
Another option would be a command line tool written in C, that you start from PHP and communicate with over stdin/stdout. In many cases this is much easier to write and to deploy, but it ultimately depends on your use case.
I was wondering if there's a decent resource for finding the inner workings of PHP.
I have taken a look at the source, but a decent explanation would really help.
Some example questions I'd like answered.
How does a PHP script get interpreted into machine readable code?
How does it interact with Apache, how does apache collect the HTML response from PHP?
And other questions like that.
It may be a bit outdated but I think you'll find this useful:
PHP internals and the Zend API
Have you taken a look at this thread on Reddit:
IAm finishing my PhD in compilers. I wrote a PHP compiler. AMA
http://www.reddit.com/r/IAmA/comments/9rpa3/for_my_fellow_geeks_iam_finishing_my_phd_in/
including the related Google Tech Talk.
The best book on te topic is Sara Golemon's Extending and Embedding PHP.
It uses PHP 5.1.0, but everything should be appliable to any 5.x. You can find information about changes to 5.3 (especially for namespaces) in the source code.
The PHP website is http://php.net/. It has a lot of information.