Hi all,
Somebody knows how this script could be made faster? I got a delay of 2-3 secs for it to load.
<?php // This script does a query on OC 9.1 contacts for a given phonenumber // Useful for Asterisk or so. // Script located at the OC Docroot // Usage: HTTP/s Request: script.php?login=<login>&pass=<pass>&asteriskquery&tel=<phonennumber> // error_reporting(E_ALL & ~(E_STRICT|E_NOTICE)); // Issue: The whole loading is slow. // Issue: getContactsManager()->search() will overwrite double TEL entries. // this happens in vCard2Array() in: // /apps/dav/lib/CardDAV/AddressBookImpl.php if (isset($_GET['login']) && isset($_GET['pass'])){ $_SERVER['PHP_AUTH_USER'] = $_GET['login']; $_SERVER['PHP_AUTH_PW'] = $_GET['pass']; } elseif(isset($_POST['login']) && isset($_POST['pass'])){ $_SERVER['PHP_AUTH_USER'] = $_POST['login']; $_SERVER['PHP_AUTH_PW'] = $_POST['pass']; } else { die(); } if(isset($_GET['asteriskquery'])){ $querynum = $_GET['tel']; require_once 'lib/base.php'; // Patched together solely from base.php $request = \OC::$server->getRequest(); $userSession = \OC::$server->getUserSession(); $userSession->tryBasicAuthLogin($request); $cm = \OC::$server->getContactsManager(); $result = $cm->search("", array("TEL")); $collect= array(); foreach ($result as $id => $arr){ foreach($arr as $key => $value) { if (preg_match("/^TEL/",$key)){ // needed or not $thistel = str_replace(" ","",$value); $thistel = str_replace(" ","",$thistel); $thistel = str_replace("+41","0",$thistel); $thistel = preg_replace("/^0041/", "0", $thistel); $collect[$thistel]=$arr['FN']; } } } // echo the FN for this TEL echo $collect[$querynum]; }