RE: [PHP] Are PHP5 features worth it?

2006-12-20 Thread Nauman Akbar
Hello!

Let us consider my scenario. I am developing a XML based web service. Using
pre PHP 5 features, I am stuck with DOM, SOAP or plain old XML parser. Too
cumbersome - eh.

I specifically upgraded my server to PHP 5 to make use of SimpleXML. I am
sure there are many other packages that are only supported on PHP 5 and are
quite useful.

I presume that is a good enough reason :). Forget about OOP and exceptions.

Regards
Nauman Akbar
Concise Solutions

-Original Message-
From: Niels [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 19, 2006 11:05 PM
To: php-general@lists.php.net
Subject: [PHP] Are PHP5 features worth it?

Hi list,

I'm writing a PHP program and I've got a number of concerns. The program is
about 20 KLOC at the moment, but will probably grow quite a lot.

I'm using OOP throughout, and I don't really have a lot of problems with
what PHP4 can do with OOP. PHP5 does have a nice feature or two, eventhough
none seems essential to my particular style of programming. I don't mind
using what PHP5 offers where it makes sense, but where's that? Exceptions
and new OOP features?

Exceptions: I just don't see the big advantage. I've got errors and messages
bubbling up through object layers as it is, and exchanging that with a
wholly new structure seems more trouble that it's worth. I've read several
books on how cool PHP5 is, but the arguments for using exceptions seem to
boil down to Java has them. Nowhere have I seen good examples that really
show how well exceptions solve real problems, all examples seem to show are
that 5 lines of try/catch are somehow sexier than 5 lines of if/else. What
about performance?

New OOP features: I can go through my code and mark all my methods as public
or private or whatever. No problem. But why would I? It will make classes
easier to understand when I look at them, but that's just convenience. What
are the performance benefits? I've not found a single mention of that
anywhere. What do abstractions and interfaces actually do, aside from
structuring my code better?

What major compelling reasons do I have to start using exceptions and OOP-5?


Thanks,
Niels

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

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



RE: [PHP] Having problem sending XML over HTTP

2006-12-15 Thread Nauman Akbar
Hello!

Thanx for reminding me that I can use a regular POST as well rather then
sending XML over HTTP directly :). Perhaps I was quite tired by then.

Anyways I tried that. Unfortunately, it seems POST data is not getting
through at all. I sent the same query with GET and it is returned fine. But
var_dump on both $_POST and $HTTP_RAW_POST_DATA return empty strings even
with a regular POST with Curl. Yes the data is urlencoded.

My server is RHEL4 with Plesk 8.x. I got PHP upgraded to PHP 5 yesterday. I
know POST requests are working fine through browser. I have tried Opera and
IE and both work just fine. So my guess is; it is probably curl causing the
problem. Can someone point me to some resource or documentation on this
issue?

Regards,
Nauman Akbar
Concise Solutions

-Original Message-
From: Brad Fuller [mailto:[EMAIL PROTECTED] 
Sent: Friday, December 15, 2006 2:16 AM
To: php-general@lists.php.net
Subject: RE: [PHP] Having problem sending XML over HTTP

 -Original Message-
 From: Nauman Akbar [mailto:[EMAIL PROTECTED] On Behalf Of Nauman
 Akbar
 Sent: Thursday, December 14, 2006 3:32 PM
 To: php-general@lists.php.net
 Subject: [PHP] Having problem sending XML over HTTP
 
 Hello!
 
 
 
 I picked up an example from Curl section on php.net. I am able to access
 the
 remote page fine with a custom header. Unfortunately, I am not able to
 retrieve the XML I am sending at the remote end. I have tried both
 $HTTP_RAW_POST_DATA and php://input but neither of them returns anything.
 I
 am putting my code below just in case anyone can point out the problem in
 there.
 
 
 
 $xmlstr = XML
 
 query
 
 usernamefff-/username
 
 passwordalphanumeric/password
 
 functionGetPackageVersion/function
 
 /query
 
 XML;
 
 
 
 $header[] = MIME-Version: 1.0 \r\n;
 
 $header[] = Content-type: multipart/mixed; boundary=doc \r\n;
 
 //$header[] = Accept: text/xml \r\n;
 
 $header[] = Content-length: .strlen($xmlstr). \r\n;
 
 $header[] = Cache-Control: no-cache;
 
 $header[] = Connection: close \r\n\r\n;
 
 $header[] = $xmlstr;
 
 
 
 print(setting urlBR);
 
 $request = curl_init(http://mrcod.concisehosting.com/index.php;);
 
 print(setting optionsBR);
 
 curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
 
 curl_setopt($request, CURLOPT_TIMEOUT, 4);
 
 curl_setopt($request, CURLOPT_HTTPHEADER, $header);
 
 curl_setopt($request, CURLOPT_CUSTOMREQUEST, 'POST');
 
 
 
 print(connecting...BR);
 
 $response = curl_exec($request);
 
 //curl_exec($request);
 
 curl_close($request);
 
 print($response);
 
 
 
 I have checked the ini file. Memory reserved for POST is 8M. Moreover, I
 even tried turning 'always_populate_http_raw_post_data' but it doesn't
 work.
 Any one any ideas, I am in real need for help on this.
 
 
 
 Regards
 
 Nauman Akbar
 
 Concise Solutions


Try this:


The code for the sending script:

?php
$xmlstr =
queryusernamefff-/usernamepasswordalphanumeric/passwordfunct
ionGetPackageVersion/function/query;

$ch=curl_init(); 
curl_setopt($ch, CURLOPT_URL, http://example.com/your-accepting-page.php;);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, xmlstr=.urlencode($xmlstr)); 
curl_setopt($ch, CURLOPT_TIMEOUT, 120); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$buffer = curl_exec($ch); 
curl_close($ch);

print_r($buffer);
?

--
The code for the receiving script:

?php

if(!empty($_POST)) {
echo You sent me some data... here is what I received:\n;
print_r($_POST);
}

?

Then open a browser and surf to the sending script.  It should print the
response from the receiving page.

Here is the output:

You sent me some data... here is what I received:
Array
(
[xmlstr] =
queryusernamefff-/usernamepasswordalphanumeric/passwordfuncti
onGetPackageVersion/function/query
)

I tested this and its working (at least on my server).

Sorry I don't have the time to tell you what is wrong with your code but
it's easier for me to just provide something that works.

I hope that helps you,

Brad

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

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



RE: [PHP] Having problem sending XML over HTTP (disregard last message)

2006-12-15 Thread Nauman Akbar
Hello again!

Please disregard my last message. Thank you Brad for reminding me to use
regular POST. I still wish I was able to send a 'text/xml' content type. But
this will do and is working great.

Regards
Nauman Akbar
Concise Solutions

-Original Message-
From: Nauman Akbar [mailto:[EMAIL PROTECTED] On Behalf Of Nauman
Akbar
Sent: Friday, December 15, 2006 5:25 PM
To: 'Brad Fuller'; php-general@lists.php.net
Subject: RE: [PHP] Having problem sending XML over HTTP

Hello!

Thanx for reminding me that I can use a regular POST as well rather then
sending XML over HTTP directly :). Perhaps I was quite tired by then.

Anyways I tried that. Unfortunately, it seems POST data is not getting
through at all. I sent the same query with GET and it is returned fine. But
var_dump on both $_POST and $HTTP_RAW_POST_DATA return empty strings even
with a regular POST with Curl. Yes the data is urlencoded.

My server is RHEL4 with Plesk 8.x. I got PHP upgraded to PHP 5 yesterday. I
know POST requests are working fine through browser. I have tried Opera and
IE and both work just fine. So my guess is; it is probably curl causing the
problem. Can someone point me to some resource or documentation on this
issue?

Regards,
Nauman Akbar
Concise Solutions

-Original Message-
From: Brad Fuller [mailto:[EMAIL PROTECTED] 
Sent: Friday, December 15, 2006 2:16 AM
To: php-general@lists.php.net
Subject: RE: [PHP] Having problem sending XML over HTTP

 -Original Message-
 From: Nauman Akbar [mailto:[EMAIL PROTECTED] On Behalf Of Nauman
 Akbar
 Sent: Thursday, December 14, 2006 3:32 PM
 To: php-general@lists.php.net
 Subject: [PHP] Having problem sending XML over HTTP
 
 Hello!
 
 
 
 I picked up an example from Curl section on php.net. I am able to access
 the
 remote page fine with a custom header. Unfortunately, I am not able to
 retrieve the XML I am sending at the remote end. I have tried both
 $HTTP_RAW_POST_DATA and php://input but neither of them returns anything.
 I
 am putting my code below just in case anyone can point out the problem in
 there.
 
 
 
 $xmlstr = XML
 
 query
 
 usernamefff-/username
 
 passwordalphanumeric/password
 
 functionGetPackageVersion/function
 
 /query
 
 XML;
 
 
 
 $header[] = MIME-Version: 1.0 \r\n;
 
 $header[] = Content-type: multipart/mixed; boundary=doc \r\n;
 
 //$header[] = Accept: text/xml \r\n;
 
 $header[] = Content-length: .strlen($xmlstr). \r\n;
 
 $header[] = Cache-Control: no-cache;
 
 $header[] = Connection: close \r\n\r\n;
 
 $header[] = $xmlstr;
 
 
 
 print(setting urlBR);
 
 $request = curl_init(http://mrcod.concisehosting.com/index.php;);
 
 print(setting optionsBR);
 
 curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
 
 curl_setopt($request, CURLOPT_TIMEOUT, 4);
 
 curl_setopt($request, CURLOPT_HTTPHEADER, $header);
 
 curl_setopt($request, CURLOPT_CUSTOMREQUEST, 'POST');
 
 
 
 print(connecting...BR);
 
 $response = curl_exec($request);
 
 //curl_exec($request);
 
 curl_close($request);
 
 print($response);
 
 
 
 I have checked the ini file. Memory reserved for POST is 8M. Moreover, I
 even tried turning 'always_populate_http_raw_post_data' but it doesn't
 work.
 Any one any ideas, I am in real need for help on this.
 
 
 
 Regards
 
 Nauman Akbar
 
 Concise Solutions


Try this:


The code for the sending script:

?php
$xmlstr =
queryusernamefff-/usernamepasswordalphanumeric/passwordfunct
ionGetPackageVersion/function/query;

$ch=curl_init(); 
curl_setopt($ch, CURLOPT_URL, http://example.com/your-accepting-page.php;);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, xmlstr=.urlencode($xmlstr)); 
curl_setopt($ch, CURLOPT_TIMEOUT, 120); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$buffer = curl_exec($ch); 
curl_close($ch);

print_r($buffer);
?

--
The code for the receiving script:

?php

if(!empty($_POST)) {
echo You sent me some data... here is what I received:\n;
print_r($_POST);
}

?

Then open a browser and surf to the sending script.  It should print the
response from the receiving page.

Here is the output:

You sent me some data... here is what I received:
Array
(
[xmlstr] =
queryusernamefff-/usernamepasswordalphanumeric/passwordfuncti
onGetPackageVersion/function/query
)

I tested this and its working (at least on my server).

Sorry I don't have the time to tell you what is wrong with your code but
it's easier for me to just provide something that works.

I hope that helps you,

Brad

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

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

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



[PHP] Having problem sending XML over HTTP

2006-12-14 Thread Nauman Akbar
Hello!

 

I picked up an example from Curl section on php.net. I am able to access the
remote page fine with a custom header. Unfortunately, I am not able to
retrieve the XML I am sending at the remote end. I have tried both
$HTTP_RAW_POST_DATA and php://input but neither of them returns anything. I
am putting my code below just in case anyone can point out the problem in
there.

 

$xmlstr = XML

query

usernamefff-/username

passwordalphanumeric/password

functionGetPackageVersion/function

/query

XML;

 

$header[] = MIME-Version: 1.0 \r\n;

$header[] = Content-type: multipart/mixed; boundary=doc \r\n;

//$header[] = Accept: text/xml \r\n;

$header[] = Content-length: .strlen($xmlstr). \r\n;

$header[] = Cache-Control: no-cache;

$header[] = Connection: close \r\n\r\n;

$header[] = $xmlstr;

 

print(setting urlBR);

$request = curl_init(http://mrcod.concisehosting.com/index.php;);

print(setting optionsBR);

curl_setopt($request, CURLOPT_RETURNTRANSFER, true);

curl_setopt($request, CURLOPT_TIMEOUT, 4);

curl_setopt($request, CURLOPT_HTTPHEADER, $header);

curl_setopt($request, CURLOPT_CUSTOMREQUEST, 'POST');

 

print(connecting...BR);

$response = curl_exec($request);

//curl_exec($request);

curl_close($request);

print($response);

 

I have checked the ini file. Memory reserved for POST is 8M. Moreover, I
even tried turning 'always_populate_http_raw_post_data' but it doesn't work.
Any one any ideas, I am in real need for help on this.

 

Regards

Nauman Akbar

Concise Solutions