CuRL Scripts?

Discussion in 'Programming' started by cagintranet, Jun 8, 2006.

  1. #1
    Does anyone here know how to turn a Curl crontab into a php script?

    example:
    25 * * * * curl --user username:password http://www.website.com/wp-content/update-feeds.php -d update=quiet
    Code (markup):
    Thanks!
     
    cagintranet, Jun 8, 2006 IP
  2. sgthayes

    sgthayes Peon

    Messages:
    171
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are 2 options :

    - run the curl command with the shell_exec() command but this isn't allowed on most hosts
    - run the curl command from within the php page :
    
            $ch = curl_init('http://www.website.com/feed.php');
    	curl_setopt($ch, CURLOPT_HEADER, 0); 
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_USERPWD, $remote_login.':'.$remote_password);
    	$contents = curl_exec($ch);
    	curl_close($ch);
    
    Code (markup):
    This way you have the results in the $contents variable. If you execute this php script in a crontab you have what you need.
     
    sgthayes, Jun 8, 2006 IP
    cagintranet likes this.
  3. cagintranet

    cagintranet Well-Known Member

    Messages:
    328
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    128
    #3
    Thanks Sgthayes... but one question. I am using the feedwordpress plugin and it requires me to open the update-feeds.php page and click submit everytime i want to update my blog.

    I think the real meat of the line of cURL i got from the FeedWordpress site was the " -d update=quiet" part at the end. he mentioned that it was the part of the code that did a $post on the page which in turn got the feeds updated.

    basically - where in the code above that you posted would i put these switches?

    Thanks... green for you for your very quick response...
     
    cagintranet, Jun 8, 2006 IP
  4. sgthayes

    sgthayes Peon

    Messages:
    171
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if the update=quiet are post vars it would go like this :

    
            $ch = curl_init('http://www.website.com/feed.php');
    	curl_setopt($ch, CURLOPT_HEADER, 0); 
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_USERPWD, $remote_login.':'.$remote_password);
            
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, 'update=quiet');
    
    	$contents = curl_exec($ch);
    	curl_close($ch);
    
    Code (markup):
    Have a look at the php curl docs for more info. Especially look at the curl_setopt() function. That's where all the good stuff is :)
     
    sgthayes, Jun 8, 2006 IP