Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error (pear not working) #30

Closed
Sogl opened this issue Mar 24, 2015 · 9 comments
Closed

Fatal error (pear not working) #30

Sogl opened this issue Mar 24, 2015 · 9 comments

Comments

@Sogl
Copy link

Sogl commented Mar 24, 2015

Hi!
I use version 1.4.0.

Code with error:

$result = $r->query('google.com', 'MX');

I see:

Fatal error: in C:\OpenServer\modules\php\PHP-5.5\PEAR\pear\Net\DNS2.php on line 1304
@mikepultz
Copy link
Owner

Hello,

So line #1304 is where it's throwing an exception- you need to wrap the query() function in a try/catch block, and catch a Net_DNS2_Exception object.

One you have that, please provide the trace and more sample code- specifically, how you're initializing the $r object.

Mike

@Sogl
Copy link
Author

Sogl commented Mar 26, 2015

Remark. Error shows only in WAMP (on LAMP pear works good).

Full code:

<?php
    error_reporting(E_ALL | E_STRICT);
    ini_set("display_errors", 1);

    require_once 'Net/DNS2.php';

    $ns = array('8.8.8.8', '8.8.4.4');
    $r = new Net_DNS2_Resolver(array('nameservers' => $ns));
    $result = $r->query('google.com', 'A');

    print_r($result);

    echo $result->answer[0]->address;
?>

Result:

Fatal error: in C:\OpenServer\modules\php\PHP-5.5\PEAR\pear\Net\DNS2.php on line 1304

But if I use try/catch:

<?php
    error_reporting(E_ALL | E_STRICT);
    ini_set("display_errors", 1);

    require_once 'Net/DNS2.php';

    $ns = array('8.8.8.8', '8.8.4.4');
    $r = new Net_DNS2_Resolver(array('nameservers' => $ns));

    try {
        $result = $r->query('google.com', 'A');

    } catch(Net_DNS2_Exception $e) {

        echo "::query() failed: ", $e->getMessage(), "\n";
    }
?>

I see:

::query() failed: The operation completed successfully. 

translated in my language.

Something strange...

@mikepultz
Copy link
Owner

Thanks,

Can you spit out the whole back-trace from the exception? Even just a print_r($e) is fine.

I wanted to find out if you're using the Sockets library to connect, or the streams code; there have been a couple issues with Sockets + Windows in the past.

if it is related to the sockets library- one quick test to confirm, would be to comment out the line:

$this->sockets_enabled = extension_loaded('sockets');

(line number 267 in Net/DNS2.php)

and then try again.

This effectively disables support for the sockets library, and uses the built-in streams functions.

Let me know,

Mike

@Sogl
Copy link
Author

Sogl commented Mar 26, 2015

Can you spit out the whole back-trace from the exception? Even just a print_r($e) is fine.

Ok (sorry for long line, I can'f find line breaks in github markdown) :

Net_DNS2_Exception Object ( [_request:Net_DNS2_Exception:private] => [_response:Net_DNS2_Exception:private] => [message:protected] => The operation completed successfully. [string:Exception:private] => [code:protected] => 203 [file:protected] => C:\OpenServer\modules\php\PHP-5.5\PEAR\pear\Net\DNS2.php [line:protected] => 1304 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\OpenServer\modules\php\PHP-5.5\PEAR\pear\Net\DNS2.php [line] => 919 [function] => sendUDPRequest [class] => Net_DNS2 [type] => -> [args] => Array ( [0] => 8.8.4.4 [1] => �F���google�com�� ) ) [1] => Array ( [file] => C:\OpenServer\modules\php\PHP-5.5\PEAR\pear\Net\DNS2\Resolver.php [line] => 212 [function] => sendPacket [class] => Net_DNS2 [type] => -> [args] => Array ( [0] => Net_DNS2_Packet_Request Object ( [rdata] => [rdlength] => [offset] => 28 [header] => Net_DNS2_Header Object ( [id] => 582 [qr] => 0 [opcode] => 0 [aa] => 0 [tc] => 0 [rd] => 1 [ra] => 0 [z] => 0 [ad] => 0 [cd] => 0 [rcode] => 0 [qdcount] => 1 [ancount] => 0 [nscount] => 0 [arcount] => 0 ) [question] => Array ( [0] => Net_DNS2_Question Object ( [qname] => google.com [qtype] => A [qclass] => IN ) ) [answer] => Array ( ) [authority] => Array ( ) [additional] => Array ( ) [_compressed:Net_DNS2_Packet:private] => Array ( [google.com] => 12 [com] => 19 ) ) [1] => ) ) [2] => Array ( [file] => C:\OpenServer\domains\zitgen\dns.php [line] => 27 [function] => query [class] => Net_DNS2_Resolver [type] => -> [args] => Array ( [0] => google.com [1] => A ) ) ) [previous:Exception:private] => ) 

if it is related to the sockets library- one quick test to confirm, would be to comment out the line:
$this->sockets_enabled = extension_loaded('sockets');
(line number 267 in Net/DNS2.php) and then try again.

Wow! It works now! =)

Can you fix it for Windows?

@mikepultz
Copy link
Owner

Yeah, I'm not too surprised that fixed it- I've had a few problems with the windows Socket library over the years.

Can you let me know what version of windows you're running? and if it's 32/64bit? I'll try to set up a test case to see if I can replicate and fix it- I might have to end up just turning off Sockets support for Windows- the streams API will work just fine in that case.

in the meantime- you can just leave that line commented out and use the streams API.

Mike

@Sogl
Copy link
Author

Sogl commented Mar 28, 2015

Can you let me know what version of windows you're running? and if it's 32/64bit?

Windows 8.1 x64

WAMP I use - OpenServer (flexy and portable):
http://open-server.ru/download/

Apache 2.4, PHP 5.5, MySQL 5.5

@mikepultz
Copy link
Owner

So the problem seems to be the MSG_WAITALL define- again.

We had this issue before- XP and below it's not defined; 2003 and 2008 it's defined, but defined as 0, where it should be defined as 8- 7 and up it's defined, but defined as 8, and it should be 0- at least- this is what I found from digging through code and testing different values.

Anyway- it seems to be inconsistent in the various versions of Windows, and I can't seem to find a way to compare Windows versions in PHP- so the best thing to do is just make Net_DNS2 use the Streams library by default on Windows.

I've checked in a fix- it basically has the same effect of just commenting out that line- so you can keep your code as-is, or grab a full copy of 1.4.1 from source control,

Mike

@Sogl
Copy link
Author

Sogl commented Mar 29, 2015

Thx, Mike!

But I can't see new 1.4.1 version:
https://pear.php.net/package/Net_DNS2/download
http://netdns2.com/

@mikepultz
Copy link
Owner

1.4.1 is the current version in trunk- it hasn't been released yet- there are some other changes i'm still working on for the next release.

So you can grab the current copy from trunk, or just keep running with the version you have- like I say- it has the same effect of just commenting out that line.

Mike

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants