How can I use C++ code to interact with PHP? [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I was reading somewhere that sometimes PHP is simply not fast enough and that compiled code has to sometimes "do the heavy lifting"
What is the api in C++ to do this?

You can add functions/classes to PHP, programmed in C (and you can wrap a C++ class from C, if I remember correctly from an article I read some time ago), which might allow you to do some things faster -- if programmed well : no need for interpretation of PHP code ; only execution of machine code, which is generally way faster.
To do that, you'll have to develop a PHP extension.
There are not that many resources available on the Internet about that, but these one might help you to start :
Extension Writing Part I: Introduction to PHP and Zend
Extension Writing Part II: Parameters, Arrays, and ZVALs
Extension Writing Part III: Resources
And, specifically about the C++ part, this one might help too :
Wrapping C++ Classes in a PHP Extension
If you are really interested by the subject, and ready to spend some money on it, you could also buy the book Extending and Embedding PHP (some pages are available as preview on Google Books too) ; I've seen a couple of times that it was the book to read when interested on this subject (In fact, I've bought it some time ago, and it's an interesting read)
By the way, the author of that book is also the author of the first four articles I linked to ;-)

You can actually execute compiled applications without any sort of API:
$output = exec('/path/to/yourapp');
Beyond that, you could always write a PHP extension. There's a good guide on the subject here: http://devzone.zend.com/article/1021

swig, the Simplified Wrapper and Interface Generator can help you wrapping (existing) c++ into a php module.
SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby.

Well you have not defined what you are trying to do, but if you need to the C++ interface, then look at the ext directory in the source code to understand how to write a PHP extension that you can then load and use from your PHP scripts.
A couple of links that may help:
http://www.devarticles.com/c/a/Cplusplus/Developing-Custom-PHP-Extensions-Part-1/
http://devzone.zend.com/article/1021

Related

How to create ORC or Parquet files from PHP code? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
Is there any library that can be used to write custom data files from a PHP app in ORC or Parquet format for Presto queries ?
If not what is the best practice in this case? Hopefully one that doesn't involve setting up Map Reduce cluster.
10X
- Nir
Sorry for bumping, but I felt this question should be updated.
Last year, I released the first publicly available PHP library for reading/writing Parquet files, php-parquet.
See https://github.com/jocoon/php-parquet and/or the published composer package https://packagist.org/packages/jocoon/parquet (composer require jocoon/parquet). It is a partial port of and inspired by parquet-dotnet, based on the Apache Thrift specifications.
As far as you don't have special compression needs (e.g. snappy), you won't need exotic PHP extensions. BCMath and GMP are required, due to the possibility of arbitrary-precision numbers and you'll need to have zlib available (AFAIK the most-used/typical compression method for Parquet files, to be more precise: gzip).
Basic usage instructions are provided on the respective github page.
DISCLAIMER: I'm the developer of this package. This is not meant as advertising. The library is published under the MIT license. Feel free to submit issues or contribute.
There is the https://github.com/apache/parquet-cpp project that provides a C++ implementation to write Parquet files without any use of MapReduce or the JVM. While there are already Python (https://arrow.apache.org/docs/python/parquet.html), Ruby / GLib (https://github.com/red-data-tools/parquet-glib) and NodeJS (https://github.com/skale-me/node-parquet) bindings, there are none yet for PHP. But given those mentioned bindings, you should be able to write ones for PHP quite easily.
We’ve Apache licensed https://github.com/skipprd/php-parquet, a PHP binding for the C++ https://github.com/apache/parquet-cpp implementation that’s been battle tested by skippr.io.
Pleased to see another effort on jocoon/php-parquet too. So now there’s a C binding and a PHP implementation to choose from! :)
DISCLAIMER: I'm the developer of this package. This is not meant as advertising. The library is published under the Apache license. Feel free to submit issues or contribute.

Calling C/C++ library function from PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
We have a PHP web app running on a customer's machine. For an update, we have a bit of code in C that we'd like to include as a native opaque library along with the PHP web app.
How does one go about calling a C/C++ lib. function from PHP?
It cannot be assumed that the PHP app, called by the web server, has any sort of permission to call an exec(), eval(), or system() type of function to execute a C wrapper driver which in turn uses the C/C++ library, so it would need to be a direct C library use from within the PHP code.
Take a look at some of the Zend tutorials on Extension writing, this one in particular "Wrapping C++ Classes in a PHP Extension"
The answer by St. John Johnson is correct. But you can now also us the php-cpp library. It offers a much easier bridge between PHP and C++. See http://www.php-cpp.com for more information.
Another option is to have the C code as a daemon, always running, and the php script connect to it throught unix domain sockets or some existing library to exchange data.
More info here
You can compile your code and use system, shell_exec or passthru functions to handle the output. Most web hosts allow you to compile c++ code, just ssh to your server, upload the code and compile it.
You can use ZEND to plug your C code into PHP.
http://php.net/manual/en/internals2.ze1.zendapi.php

Are there any artificial intelligence projects in PHP out there? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I'm interested in this field,but I'm only familiar with PHP so far.
If not,can you recommend a tiny but not so bad project that's easy enough to learn?
Take a look at Program O: https://program-o.com/
This is the description of the project:
Program O is an AIML engine written in PHP with MySQL. Here you can
find support, help, bot add-ons, a brilliant and friendly community, and of course the Program O download files.
And this mini tutorial for creating Neural Networks in PHP:
http://www.developer.com/lang/php/creating-neural-networks-in-php.html
This site could be interesting for you as well:
http://ai-php.com/
I notice many people dislike the idea of working with AI with PHP, but since most of the websites are in PHP, it will be a very interesting start to bring AI to them.
PHP Artificial intelligence links.
This is a github project and the project is beautifully active. download and use. But documentation is not complete
php-ai/php-ml
PHP-ML - Machine Learning library for PHP
There are two projects based on the ALICE project. They are Program E which isn't really developed any longer, and Program O which is. You can find them both on SourceForge
Program O https://github.com/Program-O/Program-O
Program E https://sourceforge.net/projects/programe/
Update: Program O is now on GitHub and is still developed. Program E is still orphaned and still located at sourceforge.
PHP is mostly a web-based technology as far as I know.
AI work is typically done in other languages (e.g., Lisp). But that doesn't mean you can't port the ideas to something else like PHP.
But Google found this - first hit on "PHP artificial intelligence".
There are some other samples like spam detection (bayesian networks) or OCR (using newral networks). And i'm sorry guys, php is used also in a server side scripting language and also can be converted into desktop GUI applications with PHP-GTK.
Check this php samples: http://www.phpclasses.org/browse/class/103.html
I'm also searching in this topic, but I'm looking for some kind of simple implementation of rule=based programming in PHP and I just found this http://www.swindle.net/php-rules/ in Google.
Php probably won't be the best technology for AI but there's a library for neural networks which I used to implement on a website. http://ann.thwien.de/index.php/Main_Page It's quite simple but maybe it will help you.

Difference between PHP and PHP5 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to study OOP-related PHP, mainly for mashups and some development. I started with PHP and MySQL.
What's the main relation or difference between PHP and PHP5. Is there anything different like PHP is for web development and the other PHP is for software development?
Please guide me with some books with PHP OOP examples and concepts...
Note: I am assuming by 'PHP to PHP5' you mean from PHP4 to PHP5. PHP5 is not a different languages from PHP, it is simply a different version.
PHP4 to PHP5
Here is the main differences between PHP4 and PHP5.
http://www.php.net/manual/en/migration5.php
The specific OOP changes are featured in the Object Model
http://www.php.net/manual/en/migration5.oop.php
One of the places that page points that will give you the basics to how OOP works in PHP would be the Classes and Object reference page:
http://www.php.net/manual/en/language.oop5.php
PHP Class Examples
If you want some specific examples of how OOP is used in PHP, you might want to look at my answer on some basic classes you might use in a web development setting:
https://stackoverflow.com/questions/2035449/why-is-oop-hard-for-me/2035482#2035482
Learning PHP
To learn PHP, you can do a search on PHP and OOP on StackOverflow, and the first few results give you resources to do so:
https://stackoverflow.com/search?q=php+oop
If you want to skip clicking the link, you can just go to http://php.net, cause I guarentee that almost all of them point there. PHP has one of the best documentations out there, and it is extremely easy to use, and you will return to it very, very often.
For the record, the first result talks about how to learn object-oriented programming in php.
PHP is a language. PHP 5 is a specific version of the language implementation, as opposed to 3, 4, or 6.
There are lots of alternatives to PHP. Almost any language can be used for web development via CGI, although it's more common to use a framework such as Django or Rails.
PHP5 removed register_globals, magic quotes, and safe mode. This was due to the fact that register_globals had opened security holes by intentionally allowing runtime data injection and the use of magic quotes had an unpredictable nature.

How to 3270 screen-scrape from a Linux-based web app [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I have a LAMP (PHP) web app which need to interface with programs on an IBM 3270 mainframe (via Microsoft SNA Server). One solution I'm looking at is screen-scraping via 3270. (I'm integrating the present with the past!)
Many years ago, I wrote C code which used HLLAPI as the basis for such a task.
Is HLLAPI still the best way to approach this task?
If so, would I be best off just writing a C app to undertake the work necessary and exec() this C app from php?
Are there any open source HLLAPI providers for Linux? (In the past I used commercial solutions such as Cleo.)
I haven't used it but maybe look at http://x3270.bgp.nu/ which says has a version:
s3270 is a displayless version for
writing screen-scraping scripts
I'm currently trying to do a similar thing but with a command line Python script.
I open a pipe to the s3270 (on Windows the exe name is ws3270) to connect to the server and send all commands.
Read carefully those part of the documentation for scripting:
http://x3270.bgp.nu/wc3270-man.html#Actions
http://x3270.bgp.nu/x3270-script.html#Script-Specific-Actions
While I have no experience with 3270, I would expect that finding and calling on an outside application or library is your best bet. PHP is not an all-purpose tool, hacking into a non-web communications protocols is best left to languages like C or Java that can handle that well.
Screen scraping 3270 applications is a perfectly valid way of getting at data. Many of these applications haven't changed for years, or decades in some cases. Sometimes there is simply no API or other programmatic way of getting at the necessary data.
Nighthawk: You could always learn CORBA, that monstrosity of a system was designed to let C programs talk to remote COBOL systems or random stuff written in PL/I or something.
But seriously, if the old app has no API, 3270 screen scraping is fine. There's a lot of similarities between 3270 screens and HTML forms (unlike character mode terminals).

Categories