NameSilo

Seeking php help converting fopen to curl

Spaceship Spaceship
Watch

AshleyQuick

New Member
Impact
0
Here's the part of the code that uses the fopen methodology:

PHP:
$file = SAMPLE_FILE . '.' . $zip . '.xml';
if(!file_exists($file) || filemtime($file) < time() - 3600) {
    $this->data = @file_get_contents('http://xml.mydomain.com/rss?p=' . $zip . '&u=' . $units['zap']);
    $fp = @fopen($file, 'w');
    @fwrite($fp, $this->data);
    @fclose($fd);
}
else $this->data = @file_get_contents($file);
if(strlen($this->data) <= 0) return;
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Use this for your 'if' block:

PHP:
	if(!file_exists($file) || filemtime($file) < time() - 3600) 
	{
		$ch = @curl_init('http://xml.mydomain.com/rss?p=' . urlencode($zip) . '&u=' . urlencode($units['zap']));
		$fp = @fopen($file,'w');
		@curl_setopt($ch, CURLOPT_FILE, $fp);
		@curl_setopt($ch, CURLOPT_HEADER, 0);
		@curl_exec($ch);
		@curl_close($ch);
		@fclose($fp);
	}
 
0
•••
Minor adjustments and corrections. Here's the working fragment:

PHP:
 if(!file_exists($file) || filemtime($file) < time() - 3600) 
    {
        $ch = @curl_init('http://xml.mydomain.com/rss?p=' . urlencode($zip) . '&u=' . urlencode($units['zap']));
        $fp = @fopen($file,'w');
        @curl_setopt($ch, CURLOPT_FILE, $fp);
        @curl_setopt($ch, CURLOPT_HEADER, 0);
        @curl_setopt($ch, CURLOPT_MUTE, 1);
        @curl_exec($ch);
        @curl_close($ch);
        @fclose($fp);
    }  

 $this->data = @file_get_contents($file);
 if(strlen($this->data) <= 0) return;
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back