Errors with urlencode and gzcompress

Errors with urlencode and gzcompress

am 04.12.2007 20:14:56 von James Crow

Hello all,

I am having some trouble figuring out how to pass data to a remote PHP
script.

Here is the scenario:
I have several Windows boxes running Apache 2 and PHP 4. PHP5 is not an
option because of some Zend Encoded scripts that we purchased. I need to
pass data from one script to a remote script. The local script has an
array that is serialized. Then the serialized string is then double
urlencoded. A single urlencode does not work correctly on PHP4/Win32.
The serialized and urlencoded string is then passed in the request to a
remote script: http://192.168.1.2?data=
This process works fine for small amounts of data. If the URL is below a
certain limit (maybe 1024 characters, have not yet found the exact size
limit) this works fine.

I now have a need to pass more data to the remote script. I have tried
to do
$temp = array ('lots of data...');
$temp1 = serialize($temp);
$temp2 = gzcompress($temp1); //compress our string first to save space
$temp3 = urlencode($temp2);
$data = urlencode($temp3);
http://192.168.1.1/?data=$data

Sometimes this works and sometimes not. I have not yet been able to
figure out why this sometimes fails.

Can anyone tell me why this works sometimes and others not? Or can
someone suggest a better way of passing data to a remote script.

Thanks,
James

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

RE: Errors with urlencode and gzcompress

am 04.12.2007 20:29:44 von Bill Bolte

Use Curl and pass XML...=20

-----Original Message-----
From: James Crow [mailto:james@ultratans.com]=20
Sent: Tuesday, December 04, 2007 1:15 PM
To: php-windows@lists.php.net
Subject: [PHP-WIN] Errors with urlencode and gzcompress

Hello all,

I am having some trouble figuring out how to pass data to a remote PHP
script.=20

Here is the scenario:=20
I have several Windows boxes running Apache 2 and PHP 4. PHP5 is not an
option because of some Zend Encoded scripts that we purchased. I need to
pass data from one script to a remote script. The local script has an
array that is serialized. Then the serialized string is then double
urlencoded. A single urlencode does not work correctly on PHP4/Win32.
The serialized and urlencoded string is then passed in the request to a
remote script: http://192.168.1.2?data=3D
This process works fine for small amounts of data. If the URL is below a
certain limit (maybe 1024 characters, have not yet found the exact size
limit) this works fine.=20

I now have a need to pass more data to the remote script. I have tried
to do
$temp =3D array ('lots of data...');
$temp1 =3D serialize($temp);
$temp2 =3D gzcompress($temp1); //compress our string first to save space
$temp3 =3D urlencode($temp2);
$data =3D urlencode($temp3);
http://192.168.1.1/?data=3D$data

Sometimes this works and sometimes not. I have not yet been able to
figure out why this sometimes fails.

Can anyone tell me why this works sometimes and others not? Or can
someone suggest a better way of passing data to a remote script.

Thanks,
James

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

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

RE: Errors with urlencode and gzcompress

am 04.12.2007 20:53:05 von James Crow

Curl is an option, but I would rather not add an extension to 100 remote
servers if possible. I was hoping to find a PHP native way.

Thanks,
James

On Tue, 2007-12-04 at 13:29 -0600, Bill Bolte wrote:
> Use Curl and pass XML...
>
> -----Original Message-----
> From: James Crow [mailto:james@ultratans.com]
> Sent: Tuesday, December 04, 2007 1:15 PM
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] Errors with urlencode and gzcompress
>
> Hello all,
>
> I am having some trouble figuring out how to pass data to a remote PHP
> script.
>
> Here is the scenario:
> I have several Windows boxes running Apache 2 and PHP 4. PHP5 is not an
> option because of some Zend Encoded scripts that we purchased. I need to
> pass data from one script to a remote script. The local script has an
> array that is serialized. Then the serialized string is then double
> urlencoded. A single urlencode does not work correctly on PHP4/Win32.
> The serialized and urlencoded string is then passed in the request to a
> remote script: http://192.168.1.2?data=
> This process works fine for small amounts of data. If the URL is below a
> certain limit (maybe 1024 characters, have not yet found the exact size
> limit) this works fine.
>
> I now have a need to pass more data to the remote script. I have tried
> to do
> $temp = array ('lots of data...');
> $temp1 = serialize($temp);
> $temp2 = gzcompress($temp1); //compress our string first to save space
> $temp3 = urlencode($temp2);
> $data = urlencode($temp3);
> http://192.168.1.1/?data=$data
>
> Sometimes this works and sometimes not. I have not yet been able to
> figure out why this sometimes fails.
>
> Can anyone tell me why this works sometimes and others not? Or can
> someone suggest a better way of passing data to a remote script.
>
> Thanks,
> James
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

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

Re: Errors with urlencode and gzcompress

am 04.12.2007 22:28:41 von Viola Holownia

Have you ever try JSON for data transfer?
http://json.org/

hope that helps.
You will also nend to have json.dll extension install on your php.

all the best,
Viola


On Dec 4, 2007 2:14 PM, James Crow wrote:
> Hello all,
>
> I am having some trouble figuring out how to pass data to a remote PHP
> script.
>
> Here is the scenario:
> I have several Windows boxes running Apache 2 and PHP 4. PHP5 is not an
> option because of some Zend Encoded scripts that we purchased. I need to
> pass data from one script to a remote script. The local script has an
> array that is serialized. Then the serialized string is then double
> urlencoded. A single urlencode does not work correctly on PHP4/Win32.
> The serialized and urlencoded string is then passed in the request to a
> remote script: http://192.168.1.2?data=
> This process works fine for small amounts of data. If the URL is below a
> certain limit (maybe 1024 characters, have not yet found the exact size
> limit) this works fine.
>
> I now have a need to pass more data to the remote script. I have tried
> to do
> $temp = array ('lots of data...');
> $temp1 = serialize($temp);
> $temp2 = gzcompress($temp1); //compress our string first to save space
> $temp3 = urlencode($temp2);
> $data = urlencode($temp3);
> http://192.168.1.1/?data=$data
>
> Sometimes this works and sometimes not. I have not yet been able to
> figure out why this sometimes fails.
>
> Can anyone tell me why this works sometimes and others not? Or can
> someone suggest a better way of passing data to a remote script.
>
> Thanks,
> James
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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

Re: Errors with urlencode and gzcompress

am 06.12.2007 19:24:45 von James Crow

I found a solution and figured I would share with the everyone.

I was able to switch my request method over to POST (instead of GET). I
am now doing testing to make sure that this will meet my needs, but so
far it seems to work well.

This function accepts the data to post and then returns the resulting
page. the response page does not have to be html, but I have only tested
with text. I don't know how data would work. Data to be posted should be
in name=value&name1=value1 format.

//########################################################## #########
// post_and_retrieve function
//########################################################## #########
function post_and_retrieve($host, $path, $data_to_send) {
$errno = 0;
$errstr = '';
$conn_timeout = 30;
$headers = '';
$content = '';
$flag = false;
$lc = 0;
$content_len = 0;

$fp = fsockopen($host,80, $errno, $errstr, $conn_timeout);
if (!$fp || $errno != 0 || $errstr != ''){
return "FAIL errno: $errno, errstr: $errstr";
}
fputs($fp, "POST $path HTTP/1.1\n" );
fputs($fp, "Host: $host\n" );
fputs($fp, "Content-type: application/x-www-form-urlencoded
\n" );
fputs($fp, "Content-length: ".strlen($data_to_send)."\n" );
fputs($fp, "Connection: close\n\n" );
fputs($fp, $data_to_send);
// remote script will now process the post and return a result
while (!feof($fp)) {
$res = fgets($fp,8192); //read 8k/line from remote host
if ($flag) {
if ($lc == 0) {
// first line contains the content
length in hex
$content_len = hexdec(trim ($res));
} else {
$content .= $res;
}
$lc++;
} else {
$headers .= $res;
if (strlen(trim($res)) == 0) {
$flag = true;
}
}

}
// trim our content to content_len
$content = substr ($content, 0, $content_len);
if ($headers === FALSE || strlen ($headers) < 1) {
return "FAIL could not read response content: $content";
}
fclose($fp);
//$return = array('headers' => $headers, 'content' => $content);
$return = $content;
return $return;
}

Thanks,
James



On Tue, 2007-12-04 at 14:14 -0500, James Crow wrote:
> Hello all,
>
> I am having some trouble figuring out how to pass data to a remote PHP
> script.
>
> Here is the scenario:
> I have several Windows boxes running Apache 2 and PHP 4. PHP5 is not an
> option because of some Zend Encoded scripts that we purchased. I need to
> pass data from one script to a remote script. The local script has an
> array that is serialized. Then the serialized string is then double
> urlencoded. A single urlencode does not work correctly on PHP4/Win32.
> The serialized and urlencoded string is then passed in the request to a
> remote script: http://192.168.1.2?data=
> This process works fine for small amounts of data. If the URL is below a
> certain limit (maybe 1024 characters, have not yet found the exact size
> limit) this works fine.
>
> I now have a need to pass more data to the remote script. I have tried
> to do
> $temp = array ('lots of data...');
> $temp1 = serialize($temp);
> $temp2 = gzcompress($temp1); //compress our string first to save space
> $temp3 = urlencode($temp2);
> $data = urlencode($temp3);
> http://192.168.1.1/?data=$data
>
> Sometimes this works and sometimes not. I have not yet been able to
> figure out why this sometimes fails.
>
> Can anyone tell me why this works sometimes and others not? Or can
> someone suggest a better way of passing data to a remote script.
>
> Thanks,
> James
>

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