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
Related
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 2 years ago.
Improve this question
I just started learning PHP through online videos, I have also installed notepad ++ but I am not able to installed XAMPP due to security concern as I am using the company-provided laptop,
is there any way to do practice and run my PHP program without install XAMPP
First of all, PHP is a standalone program:
PS C:\> php -r 'echo PHP_VERSION;'
7.4.5
XAMPP is just a third-party package that bundles together several famous programs written by other people. You can always get any of those programs (PHP included) from each of the official web sites.
If you mean you want to use PHP to build web applications but you aren't allowed to install a web server, you may have a couple of options:
Use PHP builtin server
Find out if your Windows edition includes IIS
If you mean that you aren't allowed to run any kind of third-party software, you're out of luck: PHP itself is software and it's third-party.
In any case: if your company is asking your to learn PHP, they should provide you with the necessary tools. If you're doing it on your own, know you're probably violating company rules anyway.
You need to have a local installed webserver. With XAMPP on your device you just have a nice tool for learning. Running a productive Application with critical data on it, would be not smart.
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.
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 7 years ago.
Improve this question
I am looking to convert my PHP library code as a PHP extension. The full library is under a namespace. There are many PHP classes I am using under my library.
Is there any tool which convert the PHP code to .so and .dll PHP extension (with the namespace usage) ?
Writing the code in C or CPP is too much of work.
There is no tool that will automagically convert PHP code to a PHP Extension, but tools like Zephir provide a half-way DSL that can easily be converted from straight PHP and then compiled against Zephir to build a PHP extension... and yes, it does work with namespaces
The Zephir docs are pretty good, and give a decent explanation of how to write code for the Zephir DSL, and there are blog posts like marmelab's that show how to convert a PHP (namespaced) class to an extension using Zephir.
Edit
Since posting this answer, I've also discovered PHP-to-Zephir which claims to be able to convert PHP code to the Zephir DSL, although I haven't tested it in any way
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
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).