Remote Webservice problem

Installing and configuring Tera-WURFL on your server.

Remote Webservice problem

Postby jhodgski » Thu Apr 07, 2011 10:41 am

Am trying to use Tera-WURFL Remote Webservice. It's set up correctly at both ends, but am getting this error when trying to access:
--------------------------------
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/xxxxxxx/public_html/TeraWurflRemoteClient.php on line 174

Warning: file_get_contents(http://xxxxxxxxxxxxxxx.xx.xx/Tera-WURFL ... port_level) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/xxxxxxx/public_html/TeraWurflRemoteClient.php on line 174

Fatal error: Uncaught exception 'Exception' with message 'TeraWurflRemoteClient Error: Could not query Tera-WURFL master server.' in /home/xxxxxxx/public_html/TeraWurflRemoteClient.php:191 Stack trace: #0 /home/xxxxxxx/public_html/TeraWurflRemoteClient.php(101): TeraWurflRemoteClient->callTeraWurfl('http://mobilewe...') #1 /home/xxxxxxx/public_html/TeraWurflRemoteClient.php(114): TeraWurflRemoteClient->getDeviceCapabilitiesFromAgent('Mozilla/5.0 (Wi...', Array) #2 /home/xxxxxxx/public_html/indexTeraWurflRemote.php(16): TeraWurflRemoteClient->getCapabilitiesFromAgent('Mozilla/5.0 (Wi...', Array) #3 {main} thrown in /home/xxxxxxx/public_html/TeraWurflRemoteClient.php on line 191
--------------------------------

Apparently, I'd need the PHP allow_url_fopen / allow_url_include directives setting to "On", but as this would also be a security concern, are there any other solutions? (E.g., is it possible so that a client's Tera-WURFL installation connects directly to my database?)

Thanks,
James
jhodgski
 
Posts: 20
Joined: Wed Apr 06, 2011 11:42 am

Re: Remote Webservice problem

Postby kamermans » Fri Apr 08, 2011 10:24 am

Wow, your web host is really making this a challenge for you, aren't they? With file_get_contents unavailable, you will have to use something like curl or straight fsock() calls. I'm going to hunt down that post with your php.ini and make sure you have curl enabled, then I can make a quick update to the remote client that supports that method.
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Remote Webservice problem

Postby jhodgski » Fri Apr 08, 2011 10:59 am

Steve,
That would be great. I'll save you the trouble of looking up my PHP info though - here's the curl info for the three websites I'm working on:

GrD site...
Configure Command: ... '--with-curl=/opt/curlssl/' '--with-curlwrappers' ...
cURL support: enabled
cURL Information: libcurl/7.20.0 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5

FOFD site...
Configure Command: ... '--with-curl=/opt/curlssl/' '--with-curlwrappers' ...
cURL support: enabled
cURL Information: libcurl/7.21.0 OpenSSL/0.9.7a zlib/1.2.3 libidn/0.5.6

GiD site...
Configure Command: ... '--with-curl' ...
cURL support: enabled
cURL Information: libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5

Also, just out of interest. My web host, doesn't allow remote access to my database, but if I could find a host that did allow this (from my customers' specified IP addresses), would it be possible to set them up with their own simple(r) Tera-WURFL installation that accessed my MySQL database directly??

Thanks,
James
jhodgski
 
Posts: 20
Joined: Wed Apr 06, 2011 11:42 am

Re: Remote Webservice problem

Postby kamermans » Fri Apr 08, 2011 11:20 am

Whew! I've already update the client to support cURL and committed it to github, I'm testing it now...

You will need to add an option to the end of the instantiation line to tell Tera-WURFL to use cURL, here's a complete example:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Remote Tera-WURFL Remote Client Example</title>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set("display_errors","On");
$start = microtime(true);
require_once realpath(dirname(__FILE__).'/../../TeraWurflRemoteClient.php');
// NOTE: You must use $FORMAT_XML to communicate with Tera-WURFL 2.1.1 and earlier!
$data_format = TeraWurflRemoteClient::$FORMAT_JSON;
$timeout = 1;
$method = TeraWurflRemoteClient::$METHOD_CURL;
$wurflObj = new TeraWurflRemoteClient('http://mydomain/Tera-Wurfl/webservice.php',$data_format,$timeout,$method);
$capabilities = array("product_info","fake_capability");
$wurflObj->getCapabilitiesFromAgent(null,$capabilities);
$time = round(microtime(true)-$start,6);
echo "<h3>Response from Tera-WURFL ".$wurflObj->getAPIVersion()."</h3>";
echo "<pre>".var_export($wurflObj->capabilities,true)."</pre>";
if($wurflObj->errors){
        foreach($wurflObj->errors as $name => $error){
                echo "$name: $error<br/>";
        }
}
echo "<hr/>Total Time: $time";
?>
</body>
</html>


It seems to be working fine, and it's about 0.0004 seconds faster (0.4 ms) :P
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Remote Webservice problem

Postby kamermans » Fri Apr 08, 2011 11:22 am

Regarding remote MySQL - yes, you can point their full Tera-WURFL install to your MySQL server, but the performance may be poor if the connection is not very fast, since this will result in a few calls back and forth (up to 20 or more if using MySQL4 connector).
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Remote Webservice problem

Postby kamermans » Fri Apr 08, 2011 11:46 am

After testing it, it seems to be working fine. Would you mind giving it a try? You can download it from https://github.com/kamermans/Tera-WURFL

Also, I've updated the documentation to include a mention of the cURL option: http://www.tera-wurfl.com/wiki/index.ph ... ervice#PHP
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Remote Webservice problem

Postby jhodgski » Fri Apr 08, 2011 2:13 pm

Steve,

It worked!! :)

I had to change line 90 to:
public function __construct($TeraWurflWebserviceURL,$data_format='json',$timeout=1,$method='curl'){
and then it was fine. Was that an oversight on your part / should I set all sites up with this new line?

Cheers,
James
jhodgski
 
Posts: 20
Joined: Wed Apr 06, 2011 11:42 am

Re: Remote Webservice problem

Postby kamermans » Fri Apr 08, 2011 2:35 pm

Ah, great! This was not an oversight, I made an additional option, so wherever you setup your TeraWurflRemoteClient, you should pass TeraWurflRemoteClient::$METHOD_CURL to the end of the constructor, like this:

Code: Select all
$data_format = TeraWurflRemoteClient::$FORMAT_JSON;
$timeout = 1;
$method = TeraWurflRemoteClient::$METHOD_CURL;
$wurflObj = new TeraWurflRemoteClient('http://mydomain/Tera-Wurfl/webservice.php',$data_format,$timeout,$method);


... or like this if you prefer to do it inline, using the default data format and timeout:

Code: Select all
$wurflObj = new TeraWurflRemoteClient('http://mydomain/Tera-Wurfl/webservice.php',null,null,TeraWurflRemoteClient::$METHOD_CURL);
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Remote Webservice problem

Postby jhodgski » Fri Apr 08, 2011 3:02 pm

Brilliant, yes, I should have read the documentation...

Just out of interest, is there any reason why $METHOD_URL_WRAPPER is the default rather than $METHOD_CURL?
jhodgski
 
Posts: 20
Joined: Wed Apr 06, 2011 11:42 am

Re: Remote Webservice problem

Postby kamermans » Fri Apr 08, 2011 3:06 pm

I will probably change it to cURL, but since I wrote this code this morning, I wanted to verify that it is as common as URL Wrappers and that its performance is similar. In version 2.1.5 I will probably use it as the default.
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Next

Return to Installation / Configuration

Who is online

Users browsing this forum: No registered users and 5 guests