Re: PHP with C++

From: Date: Mon, 09 Jun 2008 14:07:23 +0000
Subject: Re: PHP with C++
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-275145@lists.php.net to get a copy of this message
On Mon, Jun 9, 2008 at 9:11 AM, R B <rbpphp@gmail.com> wrote: > Hi, > I have a C++ script containing the function hello(x, y, z) > > I want to access this C++ function from PHP, and output with PHP the return > information. > > How can i do this? The cheating, quickest, easiest way, would be to write the function into a portable C++ script, compile it to binary form, and pass x, y, and z as argv[]'s via PHP's exec() function, like so: <?php $ret = null; // In the exec() call below, note the quotes around special characters and spaces. exec('./cpp-binary argument1 argument2 "argument three?"',$ret,$err); if(count($ret) > 1) { foreach($ret as $r) { echo $r."<br />\n"; } } elseif(count($ret) == 1) { echo $ret[0]."<br />\n"; } else { echo "Nothing returned by exec()! Error Level: ".$err."<br />\n"; } ?> -- </Daniel P. Brown> Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just $59.99/mo. with no contract! Dedicated servers, VPS, and hosting from $2.50/mo.

« previous php.general (#275145) next »