1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- /**
- * dolphin. Collection of useful PHP skeletons.
- * Copyright (C) 2019 Johannes 'Banana' Keßler
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
- *
- * You should have received a copy of the
- * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
- * along with this program. If not, see http://www.sun.com/cddl/cddl.html
- */
- /**
- * execute a curl call to the given $url
- * @param string $url The request url
- * @param bool $port
- * @return bool|mixed
- */
- static function curlCall($url,$port=false) {
- $ret = false;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
- curl_setopt($ch, CURLOPT_TIMEOUT, 30);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
- //curl_setopt($ch, CURLOPT_HEADER, true);
- if(!empty($port)) {
- curl_setopt($ch, CURLOPT_PORT, $port);
- }
- $do = curl_exec($ch);
- if(is_string($do) === true) {
- $ret = $do;
- }
- else {
- error_log(var_export(curl_error($ch),true));
- }
- curl_close($ch);
- return $ret;
- }
|