• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 661
  • Last Modified:

using curl

Hi. I am running the code attached. I am using Wamp and I have made sure that curl is enabled.
I am running it at the command prompt as follows

C:\wamp\bin\php\php5.3.0>php.exe index.php 1/1/2011 1/2/2011 "Nikkei"

but I am getting the error message:

C:\wamp\bin\php\php5.3.0>php.exe index.php 1/1/2011 1/2/2011 "Nikkei"
PHP Fatal error: Call to undefined function curl_init() in C:\wamp\bin\php\php5.3.0\index.p
hp on line 48

Fatal error: Call to undefined function curl_init() in C:\wamp\bin\php\php5.3.0\index.php on
line 48

C:\wamp\bin\php\php5.3.0>

Can anyone say what is wrong?
The php ini file says
extension=php_curl.dll.
Wamp says that curl is enabled
<?php
 
list($startdate,$enddate,$keywords)=$argv;
str_replace(" ","+",$keywords);
/*
$keywords="Tokyo+hotel+OR+ryokan+-music";
$startdate="1/1/2011";
$enddate="1/2/2011";*/
#http://www.google.com/search?hl=en&ie=UTF-8&lr=lang_en&tbm=blg&tbs=cdr:1,cd_min:1/1/2011,cd_max:1/2/2011,lr:lang_en&q=&num=100&safe=off&start=10&sa=N
$url='http://www.google.com/search?hl=en&ie=UTF-8&lr=lang_en&tbm=blg&tbs=cdr:1,cd_min:'.$startdate.',cd_max:'.$enddate.',lr:lang_en&q='.$keywords.'&num=100&safe=off';
$f=fopen('output.csv','w');
 $output=getHTML($url);
preg_match_all('@<h3 class=r><a href="http://(.+?)".+?>(.+?)</h3>.+?<span class=f>(.+?)</span>(.+?)<a@',$output, $matches);
fwrite($f, '"link","title","date","source","synopsis","text"'."\n");
for($i=0;;$i++)
{
 if( !isset($matches[1][$i]) )
 {
  break;
 }
$line="";
$line.= '"http://'.$matches[1][$i].'"';
$line.= ",";
$line.= '"'.strip_tags($matches[2][$i]).'"';
$line.= ",";
$t=split("by",$matches[3][$i]);
$line.= '"'.$t[0].'"';
$line.= ",";
if(isset ($t[1]))
{
$line.= '"'.$t[1].'"';
}
else
{
    $line.= '""';
}
$line.= ",";
$line.= '"'.strip_tags($matches[4][$i]).'"';
$line.= ',"';
$line.=html2text(getHTML('http://'.$matches[1][$i]));
$line.= "\"\n";
fwrite($f, $line);
 
}
fclose($f);
function getHTML($url)
{
    $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
// curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
// curl_setopt($ch, CURLOPT_USERAGENT, $agent);
 // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 // #curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");    // Use cookie.txt for STORING cookies
 // curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
 // $output = curl_exec($ch);
 curl_setopt($ch, CURLOPT_USERAGENT, $agent);
 if(isset($proxy) && strstr($url,'google')>0)
 {
 curl_setopt($ch, CURLOPT_PROXY, $proxy[0]);
 curl_setopt($ch, CURLOPT_PROXYPORT,  $proxy[1]);
 }
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 #curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");    // Use cookie.txt for STORING cookies

 #curl_setopt($ch, CURLOPT_COOKIE, "seen-roadblock=1;preferred_city=80");
 $output = curl_exec($ch);
 return $output;
}
function html2text($text)
{
 
$text=preg_replace('/style=".+?"/', "", $text);
       $search = array(
           "/\r/",
        "/\n/",
        '/<script.*?[^>]*>.*?<\/script>/mi',
        '/<style.*?[^>]*>.*?<\/style>/mi' ,
         '/&#\d+;/mi',
           '/[|\^#&]/mi'

    );

     $replace = array(
         '',
         '',
         '',
        '' ,
       ' ',
         ' '
    );
    $text=preg_replace($search, $replace, $text);
    $s=array(',','"',"\n");
     $text = str_replace($s, '', $text);
$text=strip_tags($text);
 


        $text= html_entity_decode($text);
       $search = array(
         '/&#\d+;/mi',
           '/[|\^#&]/mi'
           );

     $replace = array(
        '' ,
       ' ',
         ' '
    );
    $text=preg_replace($search, $replace, $text);
        return strip_tags($text);
}
?>

Open in new window

0
onyourmark
Asked:
onyourmark
  • 5
  • 3
  • 2
  • +1
2 Solutions
 
kumaranmcaCommented:
Hi,

Restart your wamp server... then test your php_info(). Curl is enabled that shown CURL separate blog...
0
 
Beverley PortlockCommented:
php.ini is for the apache module. Running from the command line uses a different php.ini or none at all. On Linux the -c switch is used to allow you to specifiy which php.ini to use

http://www.php.net/manual/en/features.commandline.php 

and in particular, this http://www.php.net/manual/en/features.commandline.options.php

0
 
AmickCommented:
It appears that you are calling curl_init properly.  Php_curl requires ssleay32.dll and libeay32.dll, are these available?

While this article specifically addresses getting curl to run with Windows, it may have some useful tips for you:
http://www.tonyspencer.com/2003/10/22/curl-with-php-and-apache-on-windows/
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
onyourmarkAuthor Commented:
Hi. I do have both of those files.
0
 
kumaranmcaCommented:
okay, Have you checked your php info details...
0
 
onyourmarkAuthor Commented:
Thanks. Here is the phpinfo details.
MSVC6 (Visual C++ 6.0)
Architecture       x86
Configure Command       cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=D:\php-sdk\oracle\instantclient11\sdk,shared" "--with-enchant=shared"
Server API       Apache 2.0 Handler
Virtual Directory Support       enabled
Configuration File (php.ini) Path       C:\Windows
Loaded Configuration File       C:\wamp\bin\apache\Apache2.2.11\bin\php.ini
Scan this dir for additional .ini files       (none)
Additional .ini files parsed       (none)
PHP API       20090626
PHP Extension       20090626
Zend Extension       220090626
Zend Extension Build       API220090626,TS,VC6
PHP Extension Build       API20090626,TS,VC6
Debug Build       no
Thread Safety       enabled
Zend Memory Manager       enabled
Zend Multibyte Support       disabled
IPv6 Support       enabled
Registered PHP Streams       php, file, glob, data, http, ftp, zip, compress.zlib, phar
Registered Stream Socket Transports       tcp, udp
Registered Stream Filters       convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, zlib.*
0
 
AmickCommented:
onyourmark,

 Did  you review the suggested article?  If so, did you have the same results when you used their test program?

On what platform are you running PHP?  Windows, LInux, something else?  
0
 
onyourmarkAuthor Commented:
I will try to check out that article. I am using Windows 7.
Thanks.
0
 
onyourmarkAuthor Commented:
Hi. I tried running it from a browser. Can you tell me how to fix the fatal error mentioned? I have already set
max_execution_time = 0



Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Deprecated: Function split() is deprecated in C:\wamp\www\googleblog\index.php on line 40

Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\googleblog\index.php on line 83
0
 
AmickCommented:
Regarding the deprecated function, it is suggested that split() be replaced by preg_split(), however str_split or explode may be appropriate depending upon what you are trying to accomplish.

Although it reports the fatal error on line 83, based on the location of split, it appears that the problem is actually at line 69,  $output = curl_exec($ch);

This may be because the URL is not properly formed.  It seems that the URL needs to be prepared before being used, try using $output=curl_exec(rawurlencode($ch));
0
 
onyourmarkAuthor Commented:
thanks so much.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now