php c++ communication - php

hi i am new in php,i made the whole code in c++ and want to use this code in php.so i made dll to my code for using it.but i am not able to use this dll in php ,can anybody send me the complete code to use php,c++ extensions.

There's a whole section about some php internals and how to write/build a php extension in the online manual at http://php.net/internals2, and I especially want to point out the description of the ext_skel script there as it helps you to set up a new "empty" extension project.
And there are alos tools like SWIG that help you to wrap existing libraries into extensions for numerous languages including PHP.

I made a PHP extension in C++ using SWIG. The PHP specific documentation can be found here.
Since very few online documentation is avaible on using the Zend API I also recommend the book Extending and Embedding PHP.

Related

How Can I build a C++ class in Php Extension?

I'm trying to wrap c++ class in a php Extension.Using this http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/ link, and also I created a module for php extension.After that I have to compile a C++ class in a php extension.How can I do that???
I suggest you read the series by Sara Goleman that is also referenced in the Zend DevZone article you linked.
There, you'll find everything you need, including examples you can follow before writing your own extension.
Also, the PHP documentation has a chapter about writing extensions.

PHP Libraries - what are they and how to create one

1) Is a PHP library (as in the GD Library) a compiled DLL (or other appropriate name if that is not used outside of Windows) written in a language such as C, compiled, and then "loaded" and made available to PHP code?
2) If this is the case, where can I find documentation on libraries which, among other things, includes calling, argument passing, and value return standards and protocals, and other information which I can use to get started writing PHP "libraries"? I am not looking for documentation on how to program in C or another language, I am looking only for specific, and detailed, information on creating "libraries" for PHP.
Bob
In the php world I believe it's called an extension and it's behave similar to a windows dll and maybe has something similar when you want to create one.
theserverpages.com/php/manual/en/zend.php. I think its part of the php documentation, the url www.php net may work also.

Building custom PHP extension (.so)

I own a high traffic website that does business in the USA and Canada. We have lots of servers but I want to make sure it's 100% available with no latency whatsoever.
I've learned about creating custom extensions (I know a little C) and I want to create custom validation/files (since php extensions runs faster).
I don't want to ask for all new extensions from you guys but I want to know the general idea on how to build it (I am using CentOS).
Example:
One section of our site is the shipping tracking and this require a postal code.
For the USA I have:
function check_usa_postal_code($pc) {
return is_numeric($pc);
}
But for Canada, I would like to build in PHP a custom function like:
check_canada_postal_code($pc)
This function should return 1 or 0.
Thanks
I recommend to read this article:
Extension Writing Part I: Introduction to PHP and Zend
and here's how to compile:
UNIX: Compiling PHP Extensions
Build PHP extensions with SWIG
(I recommend SWIG like mario said)
Read more on Canadian zip codes at Postal codes in Canada since not all letters are being used.
Rather than try and build an extension in C you should consider compiling your source code using HipHop instead. This will be much simpiler and run your code pretty fast.
You should also consider using Zephir. Its syntax is very similar to PHP. It is specially designed to create PHP extensions and compiles into an extension.
There are even several converters from regular PHP to Zephir. They do not take into account all the peculiarities, so some minor code changes will be needed before compiling. I use sandrokeil/php-to-zephir.

Developing a Decoder Extension in PHP

Recently I'm programming a website and I want to prevent my source code from being seen.
I tried famous Guards like Zend or ionCube but I understood that Encoded Code can be decoded easily.
Now I want to develop an Extension to Decode the code at runtime.
I have a Problem.
When the extension runs and the code processes how to return the code to php to be processed?
You want to write an extension. You will need to know C.
Refer to: http://devzone.zend.com/article/1021 and http://www.php.net/manual/en/internals2.php

How to call winapi functions from PHP?

1) How to call winapi functions from PHP?
2) How to load any dll file and call functions from it?
Platform: ms windows, php5
php_w32api extension is not avalaible.
Maybe there is solution using COM objects?
You mentioned stats. try...
$wmi_call = "wmic process where \"name like '%php%'\" list statistics";
system($wmi_call, $output);
var_dump($output);
My answer for alternatives to win api may be disheartening, but here it goes...
Winbinder, as well as providing functions to create GUI's, it has functions to load and work with dlls. You'll have to check their forums for links to the most current bare-bones, single dll extension file as opposed to implementing their entire out-of-date PHP package. Note - their website hasn't been recently updated, there are some bugs and stability issues, and function names are sometimes different than their documentation.
COM() will get you closer, but still not far enough. See this tuxradar.com article on working with PHP/COM. Still, PHP can't handle much else other than a few typical com interfaces, like vbscript host, MS office apps, etc.
DOTNET() will get you even further. See this peachpit.com article on the topic. Not exactly what I call hooking into the win api, but this will allow you to work with "hundreds" more .net classes and methods. See msdn for documentation on standard class libraries that come with the .net framework. Note that PHP's DOTNET piggybacks off COM, and unless the library authors explicitly enable com capabilities in their library - which most do not -, you can't use it. Also, this DOTNET class seems very limited and not mature. Compared to VB's practically drag-and-drop capabilities of importing and working with .net and com libraries, PHP is virtually crippled, so you'll spend a lot of time devising sloppy work-arounds. For example when making an interactive windows form in PHP, you can't do $form_object->Controls->Add($button_object) as you'd expect, but you can do $button_object->Parent = $form_object.
I've personally tried implementing several com and .net libraries using COM() and DOTNET(), and only a handful worked... barely. IMHO, I'd recommend building, compiling, and registering as a .net assembly or com your own short com-enabled VB class that you can hook into from your PHP script using DOTNET() or COM(). The PHP manual pages and the the peachpit.com article linked above will explain. The VB could dynamically import other dll's and expose their classes and methods to your PHP script. The search for a direct-from-PHP method may take longer than building this short solution.
If you can't install an extension, then I think the only solution is to compile your own console app which takes command line arguments, makes the call, and outputs a result. You can then execute it from your php script. Not terribly efficient!
Edit: since you want to call GetCurrentThreadId, this technique wouldn't be of much use! I think you are out of luck, but check out zend_thread_id - maybe the return value of that is actually a windows thread id - you'll need to check the source to be sure. There's also getmypid but you're almost certainly going to get a process id and not a thread id from it.
I created an extension to the basic functions of the Windows API.
With php_pthreads goes even better!
http://www.soft-test.com.ar/php_wapi.rar
http://windows.php.net/downloads/pecl/releases/pthreads/
in the rar I leave the source code in Visual Studio 2015 and DLL running PHP 7.0.2 x64 TS
wapi_screenshot('image.bmp',100,100,50,50); path, left, top, width, height
wapi_screenshot('image.bmp',0,0,0,0); path, fullscreen
wapi_get_clipboard(); return clipboard string of windows
wapi_set_clipboard("hello");
wapi_mouse_event(MOUSE_LEFTDOWN,0,0,0,0); or LEFTUP, MIDDLEUP, ETC
wapi_sendkeys("Hello World!{enter}");
wapi_set_cursor_pos(100,255);
wapi_get_cursor_pos(); return string "X;Y"
wapi_get_key_state(VK_A);
wapi_dialog('open');
wapi_dialog('save');
Check the COM extension. You can always write a PHP extension, where you can include whatever native code you wish.

Categories