PHP - How To Get Curl Timedout Exception ?
How to get cURL timedout Exception or cURL timedout Message ?
Similar TutorialsGett an error from some custom code I inherited in a WordPress installation. Here is the error... Code: [Select] Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: Failed to parse time string (--) at position 0 (-): Unexpected character' in /home2/history8/public_html/bee/wp-content/themes/makinghistoryblue/beeteachers.php:27 Stack trace: #0 /home2/history8/public_html/bee/wp-content/themes/makinghistoryblue/beeteachers.php(27): DateTime->__construct('--') #1 /home2/history8/public_html/bee/wp-includes/plugin.php(395): bee_teachers('') #2 /home2/history8/public_html/bee/wp-admin/admin.php(151): do_action('bee_teachers', Array) #3 {main} thrown in /home2/history8/public_html/bee/wp-content/themes/makinghistoryblue/beeteachers.php on line 27 Here is the code... Code: [Select] <?php $teachers = $wpdb->get_results("SELECT * FROM bee_teachers,bee_postmeta WHERE bee_teachers.statebee=bee_postmeta.post_id and meta_key='regional_date' ORDER BY meta_value ASC"); $today = new DateTime(); foreach ($teachers as $teacher): $site = get_post($teacher->statebee)->post_title; $date = new DateTime($teacher->meta_value); // this is line 27, mentioned in the error if($date<$today) $style=' style="color:#999"'; else $style=''; ?> If I remm out these lines, the query works, just no styling difference based upon date... Code: [Select] $date = new DateTime($teacher->meta_value); // this is line 27, mentioned in the error if($date<$today) $style=' style="color:#999"'; else $style=''; Thoughts? This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358486.0 good day dear community, i am workin on a Curl loop to fetch multiple pages: i have some examples - and a question: Example: If we want to get information from 3 sites with CURL we can do it like so: $list[1] = "http://www.example1.com"; $list[2] = "ftp://example.com"; $list[3] = "http://www.example2.com"; After creating the list of links we should initialize the cURL multi handle and adding the cURL handles. $curlHandle = curl_multi_init(); for ($i = 1;$i <= 3; $i++) $curl[$i] = addHandle($curlHandle,$list[$i]); Now we should execute the cURL multi handle retrive the content from the sub handles that we added to the cURL multi handle. ExecHandle($curlHandle); for ($i = 1;$i <= 3; $i++) { $text[$i] = curl_multi_getcontent ($curl[$i]); echo $text[$i]; } In the end we should release the handles from the cURL multi handle by calling curl_multi_remove_handle and close the cURL multi handle! If we want to another Fetch of sites with cURL-Multi - since this is the most pretty way to do it! Well I am not sure bout the string concatenation. How to do it - Note I want to fetch several hundred pages: see the some details for this target-server sites - /(I have to create a loop over several hundred sites). * siteone.example/?show_subsite=9009 * siteone.example/?show_subsite=9742 * siteone.example/?show_subsite=9871 .... and so on and so forth Question: How to appy this loop into the array of the curl-multi? <?php /************************************\ * Multi interface in PHP with curl * * Requires PHP 5.0, Apache 2.0 and * * Curl * ************************************* * Writen By Cyborg 19671897 * * Bugfixed by Jeremy Ellman * \***********************************/ $urls = array( "siteone", "sitetwo", "sitethree" ); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); print_r($res); ?> I look forward to your ideas. So basically I have a function that grabs a daily bible scripture via an rss feed. For whatever reason, it is offline today and I was greeted with a huge paragraph of errors and the bottom part of my page not rendering. Here is the function: Code: [Select] <?php function scripture(){ function fetchXML($url) { $ch = curl_init(); $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); //get data $data = curl_exec($ch); curl_close($ch); return $data; } define("USE_CURL", true); $url = "http://www.mybiblescripture.com/rss/bible.php?fmt=daily&trans=KJV"; //get xml doc with info $data = fetchXML($url); //create a SimpleXML object to parse the xml $char_xml = new SimpleXmlElement($data); $scripture_a=$char_xml->channel->item->description; $scripture_b=$char_xml->channel->item->title; echo $scripture_a . '<br><b>'. $scripture_b. '</b>'; } ?> And here is the nasty error I receive due to the url being offline: Code: [Select] Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /path/lbcfunc.php:21 Stack trace: #0 /path/lbcfunc.php(21): SimpleXMLElement->__construct('') #1 /path/index.php(31): scripture() #2 {main} thrown in /path/lbcfunc.php on line 21 I have 0 experience in catching exceptions and unsure where to start. I would like to try and just echo: "No Bible Scripture Found" as a friendly message instead I guess. thanks. Hey, I'm wondering what the issue is, I'm new to using PDO and objects so I'm sure this is a common error but setting me on the right track would be greatly appreciated. Code: [Select] Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND password = d41d8cd98f00b204e9800998ecf8427e' at line 1' in /Users/JPFoster/Sites/Jaipai.Blog/engine.php:47 Stack trace: #0 /Users/JPFoster/Sites/Jaipai.Blog/engine.php(47): PDO->query('SELECT * FROM u...') #1 /Users/JPFoster/Sites/Jaipai.Blog/index.php(7): SiteEngine->login('', '') #2 {main} thrown in /Users/JPFoster/Sites/Jaipai.Blog/engine.php on line 47 Code: [Select] public function login($user, $pw){ $user = addslashes($this->user); $pw = md5($pw); $query = "SELECT * FROM users WHERE username = ".$user." AND password = ".$pw; //set up query $results = $this->pdo->query($query); $num_rows = $results->num_rows; if ($num_rows == 1){ $row = $results->fetch_assoc(); echo "Worked!"; //$this->set_session($row['id'], $row['username'], $row['email']); } else { echo "Your Username and Password did not match"; } //if user + passs match { redirect (member page) and set up sessions // Else ... Retry... } } I don't see an issue with my query, and the object is instantiated by having the submit button isset() and i use login($_post[user], $_post[pw]) Hey Guys. I am across this in a book and I am having a hard time understanding how I can try/catch this expception
The code below will throw an exception if I add an unit object into Archer or LaserCannon object.
Here is a quick example
class UnitException extends Exception{} abstract class Unit{ function AddUnit(Unit $unit){ throw new UnitException(get_class($this)."is a leaf"); } function removeUnit(Unit $unit){ throw new UnitException(get_class($this)."is a leaf"); } abstract function bombardStrength(); } class Archer extends Unit { function bombardStrength(){ return 4; } } class LaserCannonUnit extends Unit { function bombardStrength(){ return 44; } } $laser_cannon = new LaserCannonUnit(); $laser_cannon->AddUnit(New Archer()); // This is not allowedWhen I run the client code I get the following error message Fatal error: Uncaught exception 'UnitException' with message 'LaserCannonUnitis a leaf' Can any please help me understand this?? Thanks! at this point, I've authenticated with the login service, and I believe I'm now passing the cookie correctly to the ADBAccess service, but when I do a soapcall to getCMSData, I'm getting an exception. Here's the relevant code: $agDataService->__setCookie('cookie', $s_Cookie); $a_includeList[0]="*"; $a_getCMSTables_args['opName']='accounts'; $a_getCMSTables_args['startDate']='01/07/2011'; $a_getCMSTables_args['endDate']='01/08/2011'; $a_getCMSTables_args['lastID']=''; $a_getCMSTables_args['includeList']= a_includeList; $agTables = $agDataService->__soapCall('getCMSData', $a_getCMSTables_args, null, new SoapHeader('http://webservice.agemni.com', 'cookie', $s_Cookie)); and here's the exception: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at ADBAccess.setErrorXML(XmlDocument& responseDoc, XmlElement& DocRoot, String ErrorMessage, Int32 ErrorNum, Int32 numRecords) at ADBAccess.getCMSData(String opName, String startDate, String endDate, String lastID, String[] includeList) --- End of inner exception stack trace --- any ideas? Hi ! I was seeing the Exception class defined in basic.php and I found that all the methods are final and without body: Code: [Select] final public function getMessage () {}But if I call MyCustomException->getMessage() I get the message. How does it works?? hello to all,
My issue is that i have a script encoded with zend and the script some pages work some are just BLANK
Zend it is installed :
This program makes use of the Zend Scripting Language Engine: Zend Engine v2.4.0, Copyright © 1998-2014 Zend Technologies with the ionCube PHP Loader v4.7.1, Copyright © 2002-2014, by ionCube Ltd., and with Zend Guard Loader v3.3, Copyright © 1998-2013, by Zend Technologies Configuration File (php.ini) Path /usr/local/lib Loaded Configuration File /usr/local/lib/php.ini and Its throwing exception he Can someone please help cuz i am tryin like a week to fix it but no results Edited by SSopranos, 07 January 2015 - 02:21 PM. Hi guys, I'm reviewing a piece of small web application and the current application does not have any error / exception handling capability. If there is any error, it would simply show an error message followed by die;. I'm planning to implement a simple exception handling class to handle the errors. What I'm thinking is a simple redirect when an error is being caught together with an error code that correspond to an error message in a simple flat text file. The error page will then show an error message that corresponds to the code. Here's what I have so far. Would appreciate if the PHP experts here would give simple pointers to enhance it. <?php class MyException extends Exception {} try { throw new MyException("error.php"); } catch (MyException $e) { $file = $e->getMessage(); header("Location: $file?e=1"); } ?> This is what I have on my error.php page <?php $errorcode = $_GET['e']; function getErrorMessage($errorcode) { $errors = file("english.txt"); foreach ($errors as $error) { list ($key,$value) = explode(",",$error,2); $errorArray[$key] = $value; } return $errorArray[$errorcode]; } echo "Test <br />"; echo getMessageMap($errorcode); ?> As you can see here, exception class would redirect user to error.php if an error is caught together with a GET variable on the URL. On error.php page, it would GET the error code and then run it through a function to get the error message of the corresponding error code and then echos it out. Was wondering if this is a good practice? My ultimate goal here is to avoid displaying the error message itself on private includes file. Thank you in advance for your suggestions. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=310162.0 In drive.php
public function insert($postBody, $optParams = array()) I'm sure it's not much, but I'm not understanding something with custom error handlers: I've created a custom error handler, which I initially set when my page loads : set_error_handler(array ( new ErrorHandler(), 'handleError' ));
It seems to catch all internal PHP errors, such as if I: var_dump($non_existing_var); right after the set_error_handler.... Now, I have an object that throws an exception after: set_error_handler(array ( new ErrorHandler(), 'handleError' )); $locale = new \CorbeauPerdu\i18n\Locale(...); // this should throw an exception ... I thought that with an error handler set, I could 'skip' the try/catch for it, but doing so, PHP spits out in its internal log: PHP Fatal error: Uncaught CorbeauPerdu\i18n\LocaleException: ....
My error handler doesn't catch it at all before, thus my page breaks!! If I want it to go through the error handler, I have to init my Locale with a try/catch and use trigger_error() like so: set_error_handler(array ( new ErrorHandler(), 'handleError' )); try { $locale = new \CorbeauPerdu\i18n\Locale(...); // this should throw an exception } catch(Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } ... Is this normal ? I thought one of the goals of the error_handler was to catch anything that wasn't dealt with? Thanks for your answers! Hi I am implementing a read-only access to some specific attributes of a class via the magic __get method. I intend to raise an exception when trying to write to it using __set, but I'm not sure which exception is suitable to use. Is there any predefined exception to indicate such an error or should I just go ahead and define my own? Hello all,
Appreciate if you folks could pls. help me understand (and more importantly resolve) this very weird error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ASC, purchase_later_flag ASC, shopper1_buy_flag AS' at line 3' in /var/www/index.php:67 Stack trace: #0 /var/www/index.php(67): PDO->query('SELECT shoplist...') #1 {main} thrown in /var/www/index.php on line 67
Everything seems to work fine when/if I use the following SQL query (which can also be seen commented out in my code towards the end of this post) :
$sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";However, the moment I change my query to the following, which essentially just includes/adds the ORDER BY clause, I receive the error quoted above: $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";In googling for this error I came across posts that suggested using "ORDER BY FIND_IN_SET()" and "ORDER BY FIELD()"...both of which I tried with no success. Here's the portion of my code which seems to have a problem, and line # 67 is the 3rd from bottom (third last) statement in the code below: <?php /* $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; */ $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY FIND_IN_SET(purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; $result = $pdo->query($sql); // foreach ($pdo->query($sql) as $row) { foreach ($result as $row) { echo '<tr>'; print '<td><span class="filler-checkbox"><input type="checkbox" name="IDnumber[]" value="' . $row["idnumber"] . '" /></span></td>';Thanks Ok, I'm new to this and I don't know much about PHP, much less Curl and how to use the functions inside of PHP: http://us.php.net/manual/en/book.curl.php However, I need to do something with this. I have to create this curl.php file, inside that file I need to take the $_POST array and send it to a different php file... I'm not sure how to do this. And yes, I only need that. I'd post the source, but my company's proprietary policies prevent me. I have a large list of websites that have allowed me to submit my website and description every 24 hours to there sites. I'm really getting tired of sitting by my computer and submitting the information to every site manually. I never understood curl and php dom stuff. does anyone have a easy code where I can post a pre scripted text of my information into three boxes and it auto submits every 24 hours to the websites? The boxes look like this Code: [Select] <input maxlength="255" value="http://" name="sPlugurl" size="20" style="font-family: Verdana; color: FE9999; font-size: 10pt; background-color: 656565; font-weight: none; border: 1px solid #0C0C0C" type="text"> <input maxlength="30" value="Sitename" name="sPlugname" size="20" style="font-family: Verdana; color: FE9999; font-size: 10pt; background-color: 656565; font-weight: none; border: 1px solid #0C0C0C" type="text"> <input maxlength="255" value="Description" name="sPlugdescription" size="20" style="font-family: Verdana; color: FE9999; font-size: 10pt; background-color: 656565; font-weight: none; border: 1px solid #0C0C0C" type="text"> <input type="submit" value="Dump" style="background-color: #656565; font-family: Verdana; color: <? echo ;?>; font-size: 10pt; border: 1px solid #0C0C0C"> the php script would auto fill out the value of the first 3 boxes with my info and then the program would submit it to there forum. I looked on google but nothing I found I can figure out? I have the following code but i can seem to log into the page can somebody tell me what is wrong please <?php error_reporting(E_ALL); $maindir = dirname(__FILE__) . DIRECTORY_SEPARATOR; include($maindir.'functions.php'); set_time_limit(0); ini_set('memory_limit','128M'); $curl_handle = curl_init(); define("SSL_CA_FILE", ".\\temp\\ssl"); define("COOKIE_FILE", "cookies.txt"); $source_file = $maindir.'login_info.txt'; // report errores error_reporting(-1); $maindir.'login_info.txt'; $fp_s = fopen($source_file, 'r'); $ch = curl_init(); //curl_followlocation set the curl to follow the site and get the final web page if the // website has redirects curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)'); // save cookie curl_setopt($ch, CURLOPT_COOKIEJAR, $maindir.'cookie.txt'); // get cookie curl_setopt($ch, CURLOPT_COOKIEFILE, $maindir.'cookie.txt'); // not to print out the results curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $account = '*****'; $password = '*****'; if(file_exists(COOKIE_FILE)) { unlink(COOKIE_FILE); } $qryString = 'email='.urlencode($account).'&pass='.urlencode($password).'&login_type=1'; curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $qryString); curl_setopt($ch, CURLOPT_URL, 'https://secure.gumtree.ie/account/login'); $page = curl_exec($ch); echo $page; // close session curl_close($ch); ?> Hi, I have server which is posting me these data through curl. $strPost = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; $strPost .= "<request>"; $strPost .= "<type>login</type>"; $strPost .= "<session>21</session>"; $strPost .= "</request>"; $url = "http://www.abc.com/xyz.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPGET,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_POSTFIELDS, $strPost); // add POST fields curl_setopt($ch, CURLOPT_POST, 1); $result = curl_exec($ch); if($result == true) { echo $result; } curl_close($ch); I wanna read the above xml send i.e $strPost at http://www.abc.com/xyz.php i m trying to read it with $_POST['strPost'] but shows empty. Can anyone help me. |