[PHP] detaching and running php processes in the background

2003-11-21 Thread Gary C. New
What is the best way to detach and run a command line based php script 
in the background from a web-based php script, without the need for 
reporting?

I have a web-based php script that gathers information and then passes 
it off to several functions, which execute several other php scripts. 
The problem is that the main php script does not return until all the 
processes have signaled and is taking about 30 sec to complete.  There 
is no need for the child processes spawned by the main php script to 
signal.  I would like to spawn and detach them to finish in the 
background; thus, dramatically reducing the load time of the main php 
script.

It has been suggested to me to use the & with the shell_exec function, 
but this still requires the child processes to signal.

Another suggestion was to use the pcntl_fork function, but my reading 
suggest that this is not to be used with web-based applications and does 
not compile in with mod_php (only the binary version).  If I were to use 
the binary version would I even be able to detach the forked child 
processes?  Doesn't pcntl_fork still require the child processes to 
signal to the parent before exiting otherwise becoming zombie processes?

Any suggestions on the best way to handle this?

Respectfully,

Gary

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: detaching and running php processes in the background

2004-01-06 Thread Gary C. New
In order to get this to work I had to do several things.

1.  I had initially compiled my php installation as a server-side 
module, but in order to execute and detach a background php process I 
had to recompile my php installation as a binary installation (hint: if 
you compile php as a binary and then as a server-side module you can 
take advantage of both installation types--that is what I ended up doing).

2.  Next you must reference the php binary with the '-f' option to 
execute the desired php script.  To pass variables, you must reference 
them in a single quoted string prefacing each with a '&' symbol. 
Finally write all signals to '/dev/null' and release it into the 
background using an ending '&' symbol.

Example:

shell_exec("/usr/local/bin/php -f ./user-create.php '&uid=" . $uid . 
"&vdomain=" . $vdomain . "&password=" . $password . "' > /dev/null &");

3.  In the primary php script (./user-create.php) escape any shell 
command variables that have been supplied by human input (security).

$u = escapeshellcmd($uid);
$d = escapeshellcmd($vdomain);
$p = escapeshellcmd($password);
4.  You should put any child commands you want to spawn in the primary 
script (./user-create.php) as this will help with maintaining the number 
of rogue processes that you might need to deal with.

shell_exec("useradd -d /home/$d $u");
shell_exec("passwd $u && $p");
That's it!

I know it sounds a bit complicated, but after you have all the right 
components functional it is quite easy.

Hope this helps all those of you who have requested it.

Respectfully,

Gary

Gary C. New wrote:
What is the best way to detach and run a command line based php script 
in the background from a web-based php script, without the need for 
reporting?

I have a web-based php script that gathers information and then passes 
it off to several functions, which execute several other php scripts. 
The problem is that the main php script does not return until all the 
processes have signaled and is taking about 30 sec to complete.  There 
is no need for the child processes spawned by the main php script to 
signal.  I would like to spawn and detach them to finish in the 
background; thus, dramatically reducing the load time of the main php 
script.

It has been suggested to me to use the & with the shell_exec function, 
but this still requires the child processes to signal.

Another suggestion was to use the pcntl_fork function, but my reading 
suggest that this is not to be used with web-based applications and does 
not compile in with mod_php (only the binary version).  If I were to use 
the binary version would I even be able to detach the forked child 
processes?  Doesn't pcntl_fork still require the child processes to 
signal to the parent before exiting otherwise becoming zombie processes?

Any suggestions on the best way to handle this?

Respectfully,

Gary

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] web-based and command line mcrypting and back again

2004-01-06 Thread Gary C. New
I am trying to figure out how to encrypt data using the web-based php 
mcrypt function and then decrypt it using the command line (cli) mcrypt 
binary, and vica-versa.

I cannot seem to get the same encrypted output for the same data, 
between the two methods.  I've tried to ensure I am using the same 
algorithms and modes for both methods by testing the mcrypt_enc_get_* 
functions.  I think the problem may lie in the way both methods are 
being seeded.

Web-Based PHP Example:

$key = 'test';
$data[] = 'abcdefghijklmnopqrstuvwxyz';
$m = 0;
foreach ($data as $dt)
{
   $td = mcrypt_module_open('tripledes', '', 'ecb', '');
   $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
   mcrypt_generic_init($td, $key, $iv);
   $CRYPT[$m] = mcrypt_generic($td, $dt);
/*
   echo mcrypt_enc_get_algorithms_name($td);
   echo mcrypt_enc_get_block_size($td);
   echo mcrypt_enc_get_iv_size($td);
   echo mcrypt_enc_get_key_size($td);
   echo mcrypt_enc_get_modes_name($td);
   echo mcrypt_enc_get_supported_key_sizes($td);
   echo mcrypt_enc_is_block_algorithm_mode($td);
   echo mcrypt_enc_is_block_algorithm($td);
   echo mcrypt_enc_is_block_mode($td);
   echo mcrypt_enc_self_test($td);
*/
   $DECRYPT[$m] = mdecrypt_generic($td, $dt);
   mcrypt_generic_deinit($td);
   mcrypt_module_close($td);
   echo "crypt_" . base64_encode($CRYPT[$m]) . "_\n";
   echo "decrypt_" . base64_decode(rtrim($DECRYPT[$m])) . "_\n";
   $m++;
}
Note:  I believe it is the line where the $iv variable is being set that 
is causing the issue and/or I cannot reproduce the same seeding using 
the command line options.

Command Line Example:

echo "abcdefghijklmnopqrstuvwxyz" | mcrypt -Fb -m ecb -a tripledes | 
encode-base64

echo "" | decode-base64 | mcrypt -dFb -m ecb -a tripledes

I would appreciate any comments or suggestions.

Respectfully,

Gary

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP/MySQL with Microsoft Word

2004-01-06 Thread Gary C. New
Use MySQLODBC...  I use it to manage my databases through MS Access.

I haven't integrated it yet with Word, but it is my intention in the 
near future.

Hope this helps.

Respectfully,

Gary

Satch wrote:
Is there any way to have a web page (PHP) that draws data from a database (MySQL) then populates a Microsoft Word document?  I have some Microsoft Word templates that are manually populated and cry out for database integration, but Microsoft Access is not robust enough.

For an even harder question:  is there a way to do the reverse?   i.e. take the populated fields from the Word document and insert the values in the database?

Thanks!



Satch
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: web-based and command line mcrypting and back again

2004-01-06 Thread Gary C. New
Tom,

I appreciate the suggestion, but even after setting the iv to zero 
within the php code and including the --noiv option within the command 
line; it still does not produce the same base64 encoded string under 
both methods.

I noticed that the command line was keying off of 2 passphrases and the 
php code off of only 1, so I forced the command line to key off of only 
1 passphrase--to no avail.

I am obviously missing something.  Someone out there has had to have 
done this at least once before.

Any other suggestions would be appreciated.

Respectfully,

Gary

Tom Rogers wrote:
Hi,

Tuesday, January 6, 2004, 8:48:17 PM, you wrote:
GCN> I am trying to figure out how to encrypt data using the web-based php
GCN> mcrypt function and then decrypt it using the command line (cli) mcrypt
GCN> binary, and vica-versa.
GCN> I cannot seem to get the same encrypted output for the same data,
GCN> between the two methods.  I've tried to ensure I am using the same
GCN> algorithms and modes for both methods by testing the mcrypt_enc_get_*
GCN> functions.  I think the problem may lie in the way both methods are
GCN> being seeded.
GCN> Web-Based PHP Example:

GCN> $key = 'test';
GCN> $data[] = 'abcdefghijklmnopqrstuvwxyz';
GCN> $m = 0;
GCN> foreach ($data as $dt)
GCN> {
GCN> $td = mcrypt_module_open('tripledes', '', 'ecb', '');
GCN> $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
GCN> mcrypt_generic_init($td, $key, $iv);
GCN> $CRYPT[$m] = mcrypt_generic($td, $dt);
GCN> /*
GCN> echo mcrypt_enc_get_algorithms_name($td);
GCN> echo mcrypt_enc_get_block_size($td);
GCN> echo mcrypt_enc_get_iv_size($td);
GCN> echo mcrypt_enc_get_key_size($td);
GCN> echo mcrypt_enc_get_modes_name($td);
GCN> echo mcrypt_enc_get_supported_key_sizes($td);
GCN> echo mcrypt_enc_is_block_algorithm_mode($td);
GCN> echo mcrypt_enc_is_block_algorithm($td);
GCN> echo mcrypt_enc_is_block_mode($td);
GCN> echo mcrypt_enc_self_test($td);
GCN> */
GCN> $DECRYPT[$m] = mdecrypt_generic($td, $dt);
GCN> mcrypt_generic_deinit($td);
GCN> mcrypt_module_close($td);
GCN> echo "crypt_" . base64_encode($CRYPT[$m]) . "_\n";
GCN> echo "decrypt_" . base64_decode(rtrim($DECRYPT[$m])) . "_\n";
GCN> $m++;
GCN> }
GCN> Note:  I believe it is the line where the $iv variable is being set that
GCN> is causing the issue and/or I cannot reproduce the same seeding using
GCN> the command line options.
GCN> Command Line Example:

GCN> echo "abcdefghijklmnopqrstuvwxyz" | mcrypt -Fb -m ecb -a tripledes |
GCN> encode-base64
GCN> echo "" | decode-base64 | mcrypt -dFb -m ecb -a tripledes

GCN> I would appreciate any comments or suggestions.

GCN> Respectfully,

GCN> Gary

try setting the iv to all 0's
$iv = 0;
$iv = pack("a".mcrypt_enc_get_iv_size($td),$iv);
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] base32/62 mcrypted data

2005-02-14 Thread Gary C. New
I am currently storing mcrypted data as a base64 encoded string.
I now need to store the mcrypted data as a base32 or base62 string, 
because of problems occurring due to the '+', '/', and '=' characters.

It seems that there is only the base64_en/decode default function.
Does anyone know of a method or a sample piece of code that can achieve 
the desired effect?

Thank you for your assistance.
Respectfully,
Gary
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Missing $GLOBALS SCRIPT_URI

2005-02-19 Thread Gary C. New
I am writing some php code that requires the $GLOBALS['SCRIPT_URI']
variable.  When I access the code under its encrypted (https) location
it is available without issue.  However, when I try to access the code
under its unencrypted (http) location it is not available.  In fact,
phpinfo() shows that there are a lot less $GLOBALS available under the
http location than there are under the https location.
I am using Apache 1.39 with Php 4.2.3.
Your comments are greatly appreciated.
Respectfully,
Gary
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Missing $GLOBALS SCRIPT_URI

2005-02-19 Thread Gary C. New
I am writing some php code that requires the $GLOBALS['SCRIPT_URI'] 
variable.  When I access the code under its encrypted (https) location 
it is available without issue.  However, when I try to access the code 
under its unencrypted (http) location it is not available.  In fact, 
phpinfo() shows that there are a lot less $GLOBALS available under the 
http location than there are under the https location.

I am using Apache 1.39 with Php 4.2.3.
Your comments are greatly appreciated.
Respectfully,
Gary
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Missing $GLOBALS SCRIPT_URI

2005-02-19 Thread Gary C. New
It turns out that SCRIPT_URI is a mod_rewrite global.
I simply had to turn the RewriteEngine On under the unencrypted (http) 
location and it worked perfectly.

Thank you for the suggestions.
Respectfully,
Gary
pete M wrote:
try
$_SERVER['SCRIPT_URI'];
Gary C. New wrote:
I am writing some php code that requires the $GLOBALS['SCRIPT_URI']
variable.  When I access the code under its encrypted (https) location
it is available without issue.  However, when I try to access the code
under its unencrypted (http) location it is not available.  In fact,
phpinfo() shows that there are a lot less $GLOBALS available under the
http location than there are under the https location.
I am using Apache 1.39 with Php 4.2.3.
Your comments are greatly appreciated.
Respectfully,
Gary

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Include Remote Content as REMOTE_ADDR of Browser

2005-05-27 Thread Gary C. New
Is there a quick and dirty way to include, file, or fsockopen content 
from a remote server and make it appear as though the request was 
straight from the browser's remote address?


Thank you for your assistance.

Respectfully,


Gary

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Compiling Phpcap

2005-05-27 Thread Gary C. New
I am trying to compile phpcap-0.2e with php-4.2.3 and get the following 
configure error:


./configure: line 52860: syntax error near unexpected token 
`PHP_NEW_EXTENSION(phpcap,'
./configure: line 52860: `  PHP_NEW_EXTENSION(phpcap, phpcap.c, 
$ext_shared)'


The phpcap INSTALL file show php-4.3.1 being used for installation.

Is there a work around for configuring phpcap-0.2e with php-4.2.3?

Thank you for your assistance.

Respectfully,


Gary

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Include Remote Content as REMOTE_ADDR of Browser

2005-05-27 Thread Gary C. New

Ryan Grange wrote:

Gary C. New wrote:

Is there a quick and dirty way to include, file, or fsockopen content 
from a remote server and make it appear as though the request was 
straight from the browser's remote address?


Thank you for your assistance.

Respectfully,


Gary



I believe you would in effect by spoofing the source of the request. The 
problem is that the server you request from would respond to the wrong 
IP and the browser at the client wouldn't be accepting any data from the 
remote server for display.




I figured that might be the case.  I guess half a solution is better 
than no solution at all.  Would it be possible to engineer a 
man-in-the-middle situation between the browser, server, and remote server?


I have been looking at Phpcap as a possible solution.  It seems possible 
to engineer the non-returnable package (half solution) situation.  But I 
wouldn't know where to begin to attempt the man-in-the-middle situation 
or if it is even possible.


Thank you for your response.

Respectfully,


Gary

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php