Seeking php help converting fopen to curl

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
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
Close
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
Close
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
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

A browser tab with a favicon next to the page title
Search members
You can now search for members by name, company, location and more. Open the search at the top of any page and choose Members. You will...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back