473,773 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

proc_open hang (data > 64k)

Hi,

I've written something that takes text and passes it to gpg to encrypt.
It works great except when the text size is greater than 64k at which
point PHP/Apache hangs. Is there any way around this? Below is a code
snippet (which may or may not help).

Thanks,
-r

function encryptContent( $fileContent, $encryptionKey)
{
if(!$this->gpgVerify())
{
$this->displayTextInT able('gpgVerify failed!');
exit;
}

$command = '/safeModeExecDir/gpg --homedir /data/.gnupg --armor
--cipher-algo AES256 --passphrase-fd 3 --batch
--no-tty --yes -c';

// set up pipes for handling I/O to/from GnuPG
// 0 === STDIN, a pipe that GnuPG will read the content from
// 1 === STDOUT, a pipe that GnuPG will write the encrypted
content to
// 2 === STDERR, a pipe that GnuPG will write to
// 3 === STDIN, a pipe that GnuPG will read the passphrase from
$descriptorSpec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w"),
3 => array("pipe", "r")
);

$gpgProcess = proc_open($comm and, $descriptorSpec , $gpgPipes);

if(is_resource( $gpgProcess))
{
// this writes $fileContent to GnuPG on STDIN
if(false === fwrite($gpgPipe s[0], $fileContent,
strlen($fileCon tent)))
{
$this->displayTextInT able('fwrite failed!');
exit;
}
fclose($gpgPipe s[0]);

// this writes the $encryptionKey to GnuPG on fd 3
fwrite($gpgPipe s[3], $encryptionKey) ;
fclose($gpgPipe s[3]);

// this reads the encrypted output from GnuPG from STDOUT
$encryptedConte nt = '';
while(!feof($gp gPipes[1]))
{
$encryptedConte nt .= fgets($gpgPipes[1], 1024);
}
fclose($gpgPipe s[1]);

// this reads warnings and notices from GnuPG from STDERR
$gpgErrorMessag e = '';
while(!feof($gp gPipes[2]))
{
$gpgErrorMessag e .= fgets($gpgPipes[2], 1024);
}
fclose($gpgPipe s[2]);

// this collects the exit status of GnuPG
$processExitSta tus = proc_close($gpg Process);

// unset variables that are no longer needed
// and can only cause trouble
unset(
$fileContent,
$encryptionKey,
$command,
$descriptorSpec ,
$gpgProcess,
$gpgPipes,
$gpgErrorMessag e,
$gpgExitStatus
);
}
else
{
$this->displayTextInT able('proc_open () failed.');
exit;
}

return $encryptedConte nt;
}

Oct 26 '05 #1
2 3204
>I've written something that takes text and passes it to gpg to encrypt.
It works great except when the text size is greater than 64k at which
point PHP/Apache hangs. Is there any way around this? Below is a code
snippet (which may or may not help).


If you try to set up a two-way set of pipes between a parent and a
child (in any language, on a POSIX-like OS), you're just begging
for deadlock. Especially if you can't modify the source code of
the child and it just expects to act like a filter. Stdio buffering
may create deadlock where you wouldn't otherwise expect it. There
are a couple of possible solutions:

(1) Put either the input or the output in a temporary file rather
than a pipe. You can do both, but that's overkill.
(2) Use non-blocking reads/writes and poll or select.
(I haven't looked at whether this is possible with PHP).
(3) Some types of filters avoid deadlock, for example, sorting
produces no output until all the input has been read.

Gordon L. Burditt
Oct 26 '05 #2
>(2) Use non-blocking reads/writes and poll or select.
(I haven't looked at whether this is possible with PHP).


You can set the blocking mode of streams (including pipes) using
stream_set_bloc king() :

<http://www.php.net/manual/en/function.stream-set-blocking.php>

Oct 26 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5852
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child
0
2294
by: Christian Hammers | last post by:
Hello I would like to call a unix shellscript from within a PHP script and - write data to its STDIN - read data from its STDOUT *and* STDERR - get its exit code afterwards proc_open seems to be the right thing to use but I have the problem that the called program gives >8kb data on both stdout/stderr back which causes my PHP script to simply hang in the fread call. To be precise the first 4096 "O" characters are read and displayed. ...
4
3154
by: FLEB | last post by:
I like PHP for its excellent inline integration into standard HTML files, but I like Perl for its quick-moving syntax and simpler data-processing. To resolve this deep-seated inner turmoil (oh, the drama) I've been trying to think of good ways to get Perl code to run inline in a PHP script. Here are a few of my ideas. If anyone has any further ideas, resources, or knows of someone else who's solved this already, please do tell... 1.) The...
0
2073
by: FrenKy | last post by:
Hi *. I get this error when trying to run proc_open() function: "Fatal error: Call to undefined function: proc_open() in /home/frantic/public_html/a/phpshell.pup on line 140" Does anybody knows what setting I have to change to fix this? Configuration:
4
1687
by: Anurag | last post by:
I feel really embarassed asking this. However, ask I will. When we say that: (1) "CLP in Db2 V8.2 still imposes a limit of 64K on the stored proc size; (2) "....If you use another client, such as command center or development center the SP size limit is 2MB"; (3) "Statement size has been increased to allow 2M in Stinger"
6
1606
by: Barry | last post by:
Hi all I have this script(download.php) which downloads binary data from a mysql database. <? /* SNIP */ $document=document::singleton();
0
1060
by: Rashid Karim | last post by:
I have a java application on java Swing, EJBs, Bea WebLogic, and Oracle. When I run a long query in batch, I get this message: java.sql.SQLException: Oracle cannot handle batched SQL > 64k bytes but when I copy that query in PL/SQL developer, there is no problem. Whats the limitations in batch execution of sql statements. kindly help me.
5
3107
by: sakismat | last post by:
please help how can I get stderr from processes ($proc) in my screen without waiting the other processes to end #!/usr/bin/php <?php $con = mysql_connect("localhost", "user"); if (!$con)
6
5475
by: xhe | last post by:
I am using ffmpeg to convert video, this is a sample script: $str='/home/transla1/bin/ffmpeg -i /home/transla1/public_html/ cybertube/web/uploads/video/31_AK000005.AVI -s 240x180 -b 100k -ar 22050 -y /home/transla1/public_html/cybertube/web/uploads/video/ generated/31_70_AK000005.AVI.flv '; //exec($str); runExternal($str,$code); echo $code ;
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.