2

I'm trying to open a Windows Handle, which I know it can be opened in C#. But what I want to achieve is to open it directly in PHP. I know the process and the name of the handle. What I have in head is to make a PHP script in CLI that can wrap the data in the handle, which is binary encoded. So, is there a way to open such ressource directly with PHP-CLI?

I'm not searching for an interface, so "read it with C# and sent it with local network to PHP" is not the answer I'm searching for.

Regards.

JumpIfBelow
  • 53
  • 2
  • 11
  • This reads strange... I assume you want to use php an the command line, not within an http server? Because otherwise that would not make any sense... It might help to get answers if you could be a little more precise and explain what you want to do... – arkascha Aug 01 '15 at 08:59
  • Yes, the goal is to use it with CGI, not with HTTP. I will try to be more accurate with my question. – JumpIfBelow Aug 01 '15 at 09:00
  • 2
    CGI would also mean triggered by HTTP... Or do you man CLI? – arkascha Aug 01 '15 at 09:01
  • Anyway, I doubt there is a php extension for this. Such thing simply is not what php what build for. Yes, you can perform local tasks with it. But in its character php is pretty system agnostic. So I doubt you will find many options to deal with MS-Windows specific internals. php is more at home in unixoid environments, since it was build for the web, which is dominated by non-MS-Windows systems. But maybe you want to implement such an extension if you have need for it? PHP is OpenSource, so nothing speaks against it! – arkascha Aug 01 '15 at 09:03
  • Yes, you have a point, I meant CLI... So far, yes I really have to deal with the fact that PHP is made more for UNIX. There is no IPC for Windows in PHP, as far as I know. Maybe with system call I can read such handle, so this way I will be able to read it directly in PHP, with a wrapper. But I really searched hard to find a way to do this – JumpIfBelow Aug 01 '15 at 09:09
  • There's a COM extension for PHP in a Windows environment. I have no idea whether it will enable you to do what you want, but you can find the reference [here](http://php.net/manual/en/book.com.php) –  Aug 01 '15 at 09:10
  • Like `$WshShell = new \COM('WScript.Shell');`? And `$cmd = 'cmd /C '.$phpPath.' '.$script;` .. C/P from my windows background script .. shh. Just a note anyone reading this I highly recommend using this on your `escapeshellarg($script)`, just saying. And, this bit too `$WshShell->Run($cmd, 0, false)` – ArtisticPhoenix Aug 01 '15 at 09:24
  • @HoboSapiens THanks for sharing. I actually doesn't have knowledge to use .NET. It's worth trying, but I really doesn't know how to use this extension. – JumpIfBelow Aug 01 '15 at 09:30
  • Do you mean a pipe, I don't know what a `Windows Handle` is http://stackoverflow.com/questions/902967/what-is-a-windows-handle For a pipe you can use `popen` http://php.net/manual/en/function.popen.php – ArtisticPhoenix Aug 01 '15 at 09:31
  • @ArtisiticPhoenix this should be helpful to run a command, but this is not really a clue to access to a handle. – JumpIfBelow Aug 01 '15 at 09:32
  • @JumpIfBelow - yes but one may be surprised at how hard it is to execute a background process from php on windows, those 3 lines .. gold. pure gold – ArtisticPhoenix Aug 01 '15 at 09:36
  • @ArtisiticPhoenix a pipe is a way to route the stdout of a cmd to the stdin of another cmd. The Windows Handle I'm talking about is more like a shared memory in UNIX. – JumpIfBelow Aug 01 '15 at 09:37
  • Perhaps this http://php.net/manual/en/function.shm-attach.php Shazam – ArtisticPhoenix Aug 01 '15 at 09:39
  • @ArtisiticPhoenix Unfortunetely, it's not the magic solution. All you can do with this is using shared memory in UNIX, not Windows Handle. It's quiet the same thing but not the same impletentation. – JumpIfBelow Aug 01 '15 at 10:12
  • @JumpIfBelow ~ sorry I couldn't help. I only touched C# one time and I got a tummy ache from it. Could you run a C# script from PHP to do it, or a Java or bash script, just a wild thought. – ArtisticPhoenix Aug 01 '15 at 20:02

0 Answers0