]> 91.132.146.200 Git - dolphin.git/commitdiff
simple curl call
authorBanana <banana@optimus.de>
Tue, 16 Jul 2019 13:50:38 +0000 (15:50 +0200)
committerBanana <banana@optimus.de>
Tue, 16 Jul 2019 13:50:38 +0000 (15:50 +0200)
single-functions/simple-curl-call.php [new file with mode: 0644]

diff --git a/single-functions/simple-curl-call.php b/single-functions/simple-curl-call.php
new file mode 100644 (file)
index 0000000..ebc4f66
--- /dev/null
@@ -0,0 +1,50 @@
+<?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;
+}