The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 16, 2019, 11:17:06 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Need Some Help. Curl/PHP Issue?  (Read 2954 times)
Con
Rookie
**
Offline Offline

Posts: 20


Who's Next?


View Profile
« on: June 20, 2008, 05:19:05 PM »

I'm totally confused by this and hoping one of you can solve it for me.

I have the following which basically is running a script that checks if an IP is in a mysql db and then echo's out the results of that script which will be "yes" if it's there or "no" if not. I've changed actual site names but the point is that it doesn't work on one server I have, but it does work on the other. On the one where it does NOT work, it takes way too long and returns just a blank page. The one that does work just immediately returns yes or no based on whether the IP is there or not.

Curl is enabled on both servers and actually, both have the same version of PHP 4.4.8 I believe. Any suggestions? I am missing or enabling something on the bad server that is causing this, but I'm too damn ignorant to know what is.

I GREATLY appreciate any help you guys might offer.

Thanks,
Con  Huh?

<?php
$url1="http://mydomain.com/getip.php";
$visitor = $_SERVER['REMOTE_ADDR'];

$site_url = $url1. "?ip=" . $visitor;

$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $site_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

ob_start();
curl_exec($ch);
curl_close($ch);
$f1 = ob_get_contents();
ob_end_clean();

echo $f1;
?>
Logged

I can't code. I'm just here to annoy all of you!
Con
Rookie
**
Offline Offline

Posts: 20


Who's Next?


View Profile
« Reply #1 on: June 20, 2008, 08:06:07 PM »

Ok,
I have more feedback on this issue which might get me an answer from one of you.

I went through each server and made sure every single option for php was the same. Identical apache versions and identical options for php. Didn't make much of a difference.

However....

I fixed my test script and came up with the conclusion that it's very intermittent. Sometimes it actually will contact the DB and sometimes it doesn't. I had it echo different values based on what's happening. It makes no sense to me though. Why would it work and literally 30 seconds later it won't? Is this a DNS issue? But that doesn't make sense because it works 100% of the time on the other server. On top of that, the mysql db is on a domain on the server that is NOT working properly yet the same exact script will access it successfully every time from the other server.

I tried this with file_get_contents too (instead of curl) on this bad server and got the same exact results, works for a bit and a minute later it doesn't. I can refresh a test page 5 times in a row and it works fine, the 6th time it will hang up and return a value indicating that it couldn't contact the DB.

Any ideas? If not a fix then a workaround maybe?

This is killing me as I can't cloak a page if I can't access the freaking IP DB  consistently.  Don't make me...

If anyone can help, I appreciate it.

Have a good weekend,
Con
Logged

I can't code. I'm just here to annoy all of you!
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #2 on: June 20, 2008, 08:46:28 PM »

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

I'm surprised it's returning anything to the buffer at all without that set...
Logged

hai
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #3 on: June 21, 2008, 07:42:53 AM »

could you just avoid curl and use file_get_contents?

if its not what V suggested, then is the machine that works also the machine with the DB on it? if it is, that could be why, since DNS will cache as a local IP (or at least only make it to the first router). is the bad box on a completely different service provider? ping flood that box and see if it drops packets regularly, if so, bitch to tech support.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
thedarkness
Lifer
*****
Offline Offline

Posts: 585



View Profile
« Reply #4 on: June 21, 2008, 06:28:01 PM »

error_reporting(E_ALL);

Right at the top bro and run it again. Also, not sure but you might want an ob_flush() in there.

Cheers,
td
Logged

"I want to be the guy my dog thinks I am."
 - Unknown
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: June 23, 2008, 02:23:16 PM »

Con - you might try downloading the webrequest2 class from the repository here, then set the debug level to WRD_ECHO - it'll spit out a whole bunch of stuff that might help you ascertain where, exactly, the fault is happening. Your code can be as simple as this:

require "class.webrequest2.php";
$req = new webRequest2();
$req->debugMode = WRD_ECHO;
$req->simpleGet('http://yourdomain.com/aurl.html');

... won't fix the problem, but might tell you where it is - especially if it's intermittent. Good luck man!

/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Con
Rookie
**
Offline Offline

Posts: 20


Who's Next?


View Profile
« Reply #6 on: June 28, 2008, 09:53:45 AM »

Thanks to all of you. I really appreciate the help.

At the end of the day, it looks like this was a DNS issue on the hosts end. While they finally resolved it, I was too pissed off and ended up moving to a new server. MUCH happier now.  Grin

But I also learned a whole lot from here too and will put that code to good use in the future.

Gracias Amigos,
Con
Logged

I can't code. I'm just here to annoy all of you!
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!