Curl no working in PHP CLI SAPI -
my php curl script not recognize curl_init(); resource lots of errors follow. bellow cli output clarify.
note aware of $url issue trying solve 1 problem @ time( either issue appreciated:)):
php notice: undefined variable: url in /var/www/jobbotback/getsite.php on line 9 php stack trace: php 1. {main}() /var/www/jobbotback/getsite.php:0 php 2. website->exec() /var/www/jobbotback/getsite.php:29 php notice: undefined variable: ch in /var/www/jobbotback/getsite.php on line 18 php stack trace: php 1. {main}() /var/www/jobbotback/getsite.php:0 php 2. website->exec() /var/www/jobbotback/getsite.php:29 php 3. website->info() /var/www/jobbotback/getsite.php:11 php warning: curl_error() expects parameter 1 resource, null given in /var/www/jobbotback/getsite.php on line 18 php stack trace: php 1. {main}() /var/www/jobbotback/getsite.php:0 php 2. website->exec() /var/www/jobbotback/getsite.php:29 php 3. website->info() /var/www/jobbotback/getsite.php:11 php 4. curl_error() /var/www/jobbotback/getsite.php:18 php notice: undefined variable: ch in /var/www/jobbotback/getsite.php on line 19 php stack trace: php 1. {main}() /var/www/jobbotback/getsite.php:0 php 2. website->exec() /var/www/jobbotback/getsite.php:29 php 3. website->info() /var/www/jobbotback/getsite.php:11 php warning: curl_getinfo() expects parameter 1 resource, null given in /var/www/jobbotback/getsite.php on line 19 php stack trace: php 1. {main}() /var/www/jobbotback/getsite.php:0 php 2. website->exec() /var/www/jobbotback/getsite.php:29 php 3. website->info() /var/www/jobbotback/getsite.php:11 php 4. curl_getinfo() /var/www/jobbotback/getsite.php:19 php notice: undefined variable: ch in /var/www/jobbotback/getsite.php on line 15 php stack trace: php 1. {main}() /var/www/jobbotback/getsite.php:0 php 2. website->close() /var/www/jobbotback/getsite.php:30 php warning: curl_close() expects parameter 1 resource, null given in /var/www/jobbotback/getsite.php on line 15 php stack trace: php 1. {main}() /var/www/jobbotback/getsite.php:0 php 2. website->close() /var/www/jobbotback/getsite.php:30 php 3. curl_close() /var/www/jobbotback/getsite.php:15
here code being executed:
<?php class website { function seturl($param) { $url = $param; } function exec() { $ch = curl_init(); curl_setopt( $ch, curlopt_returntransfer, true); curl_setopt( $ch, curlopt_url, $url); $site = curl_exec($ch); $this->info(); return $site; } function close() { curl_close($ch); } function info() { if(!curl_error($ch)) { $info = curl_getinfo($ch); echo $info; } else { $error = curl_error($ch); echo $error; } } } $test = new website; $test -> seturl('www.google.com'); $content = $test -> exec(); $test ->close(); echo $content;
what bothers me fact /etc/php5/cli/php.ini
returns nothing when enter /curl
in vim, tried on web should php.ini no luck.
you referring variables in class methods don't exist. define $ch
in exec
, , close in close
, not storing reference $ch
@ class level. add $ch
property class , change references $ch
$this->ch
. same true $url.
class website { private $ch; private $url; function seturl($param) { $this->url = $param; } function exec() { $this->ch = curl_init(); curl_setopt( $this->ch, curlopt_returntransfer, true); curl_setopt( $this->ch, curlopt_url, $this->url); $site = curl_exec($this->ch); $this->info(); return $site; } function close() { curl_close($this->ch); } function info() { if(!curl_error($this->ch)) { $info = curl_getinfo($this->ch); echo $info; } else { $error = curl_error($this->ch); echo $error; } } }
Comments
Post a Comment