Jump to content

[SOLVED] This worked until recently - any ideas please?


eldoc

Recommended Posts

Hi guys

 

This code (below) worked fine on my website (I have taken out all of the extraneous stuff) until a month ago.  It also worked on my local EasyPHP server and still does. 

 

My guess is that either

[1]  an update to php no longer allows it to work (seems very unlikely!)

[2]  the server has changed its settings in some way

 

Any ideas please.

It has always produced a few lines of data (still does on local server) but now just runs - there are no errors just $str is blank instead of full of data.

 

 

Cheers

 

Eldoc

 

 

 

<?

$fp = fsockopen("udp://195.149.21.12", 21000, $errno, $errstr,2);

 

stream_set_timeout($fp,1);

 

if (fwrite($fp,"\\status\\") === false){

die();

}

 

$str = fread($fp, 65000);

$str = $str.fread($fp, 65000);

fclose($fp);

 

echo "<br>".$str."<br>";

?>

Link to comment
Share on other sites

Id'e start by replacing <? with the full <?php tags. You might also wrap your call to fsockopen in some error handling.

 

<?php

if ($fp = fsockopen("udp://195.149.21.12", 21000, $errno, $errstr,2)) {

 stream_set_timeout($fp,1);

 if (fwrite($fp,"\\status\\") === false){
   die();
 }

 $str = fread($fp, 65000);
 $str = $str.fread($fp, 65000);
 fclose($fp);

 echo $str;
} else {

 echo $errstr;
}

?>

Link to comment
Share on other sites

Thanks for the prompt reply guys :-

 

[1] yes, I can still connect with the same programme from my local server and used to be able to connect from my site until a month ago

 

[2] it's the same with <?php

 

[3] as stated I have taken out all of the error checking and other stuff to make it as easy to follow as possible.  $fp comes back with a handle and no errors.

 

Many thanks

 

Eldoc

Link to comment
Share on other sites

change this bit,

 

  if (fwrite($fp,"\\status\\") === false){
    die();
  }

 

to

 

  if (fwrite($fp,"\\status\\") === false){
    die("I am dead");
  }

 

What happens?

Link to comment
Share on other sites

I think the underlying problem is your web host then or the address your trying to access. Something has changed there and it sounds like an authentication issue. Perhaps the udp your trying to access has an allow list with certain server IPs, your webhost has changed its IP and is no longer allowed.

 

That is where I would start looking, I doubt this is a PHP issue.

Link to comment
Share on other sites

UDP connections will always come back with a handle, even if the destination is inaccessible.  All that you'll see is that no data comes back.  That's just the way it is unfortunately.

 

If your webhost started blocking that udp port, then the behaviour you see would be consistent with that.

Link to comment
Share on other sites

Many thanks guys - that was what I suspected - my ISP claims nothing has changed - the server I am getting data from has definitely not changed because I have full rights there and can check anything.

 

I will mark this as 'SOLVED' to save anyone wasting more time on it.  Thanks to all for taking the time to offer ideas.

 

Cheers

 

Eldoc

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.