Windows Azure SDK for PHP requires allow_url_fopen - php

The MSDN forums have not been very helpful so I am reposting my question here.. I am trying to use the new Windows Azure SDK for PHP to download a blob using
$blobRestProxy =
ServicesBuilder::getInstance()->createBlobService($connectionString);
$blob = $blobRestProxy->getBlob($container, $blobname);fpassthru($blob->getContentStream());
The problem is that in the WindowsAzure\Common\Internal\Utilities.php file stringToStream() is returning a warning which causes the download to fail when allow_url_fopen is Off:
PHP Warning: fopen(): data:// wrapper is disabled in the server
configuration by allow_url_fopen=0
My question is whether this is an isolated problem or does the new SDK require allow_url_fopen to be On in order to use the getBlob function? Is there an alternative where I can avoid having to turn on allow_url_fopen?

The SDK uses fopen for REST API queries (also for Blob requests). Because REST APIs have a URI Scheme, you need allow_url_fopen to be turned ON.
What kind of alternative are you looking for? The only alternative I see, is to modify the SDK code to avoid the usage of fopen. Maybe with cUrl? But I would not recommend it either...

Related

google app engine won't recognize contents of php.ini

I'm trying to use curl in the google app engine, but it gives this error:
Uncaught Error: Call to undefined function curl_init()
HP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/curl.so' - /usr/lib/php/20151012/curl.so: cann
ot open shared object file: No such file or directory in Unknown on line 0
ERROR:root:php failure (255)
I searched, and found that the curl is disabled, and that i had to create a php.ini file with this code inside:
extension = "curl.so"
I also read that it could be a problem of versions of the service, so i did it in the getting started of the app engine(first version).but it did not work.
But it seems that the php.ini is not recognized by the app engine,someone could help me how could i POST using curl or another way
There are two things that you should also keep in mind:
cURL is only available for applications with billing enabled as stated in the documentation.
In your php.ini you have both cURL and cURLite enabled which is incorrect. Only one of those can be enabled and not both at the same time.
You can deploy sample application following the steps provided, which will get you started using cURL with PHP in App Engine Standard.
For other methods of issuing HTTP(S) requests using PHP, refer to the documentation here.

PHP Quickbooks API issue with allow_fopen_url

I am using Quickbooks PHP API and it is working fine when we set allow_url_fopen to true.
But when we set allow_url_fopen to false then this API is not
working.
I found that fetch function of OAuth library is not getting any
response.
When I debug, it gives error like this "Fatal error: Uncaught
exception 'OAuthException' with message 'making the request failed
(dunno why)' "
For use OAuth, we have to set allow_url_fopen to true?
allow_url_fopen allows functions such as fopen, fsockopen to be URL aware, as a result, these functions can read remote data. If you turn this setting off, these functions are no longer URL aware, which means you cannot use URL to open a file. I suspect the API is using these function(s) to allow for remote connections. This setting is a security feature, which stops your scripts from accessing remote files.

Openssl php not working

I am trying to build a twitter feed to search for relevant hashtags and display them in my mobile app. I found a package at http://mlemos.users.phpclasses.org/package/8109-PHP-Generate-RSS-feeds-from-timelines-and-searches.html that seems to do the job. However, opensll isnt loading. i get Error: it was not possible to open the API call URL: establishing SSL connections requires the OpenSSL extension enabled. Now, i have used open ssl on this machine before, and phpinfo says it is enabled. i have checked my php.ini file to make sure the line is uncommented, as well as check my path variable. No success. Google has turned up nothing helpful. Any ideas? Thanks
Ended up using a twitAPI handler package

Writing a simple text file to Google Cloud Storage from PHP

When I try to use the sample code:
$fp = fopen("gs://my_bucket/some_file.txt", "w");
fwrite($fp, "Hello");
fclose($fp);
I get this error:
Warning: fopen(): Unable to find the wrapper "gs" - did you forget to enable it when you configured PHP?
UPDATE
Switching to running the app server from the command line made the original error go away but I now get this error:
'google\appengine\runtime\RPCFailedError' with message 'Remote implementation for urlfetch.Fetch failed'
Does anyone know how I can resolve it?
Where are you seeing this error? On the production server, testing locally using our SDK or are you not using the SDK?
We install this handler as part of our setup script, so you need to be running in the dev appserver if your testing locally.
You have to use dev_appserver.py (from GAE PHP SDK) to check your code locally. Do not run it through your local webserver, since it will not provide additional plugins (for example gs: stream support) and won't emulate "whole" GAE environment (Datastore, Memcache, Tasks etc.).
On Debian following should work:
sudo apt-get install php5-cgi
/path/to/google_appengine/dev_appserver.py --php_executable_path=/usr/bin/php-cgi .
assuming that:
you have downloaded and installed GAE PHP SDK
you're in your GAE test application directory
You will have to enter localhost website on port 8080 to check if you have your app working. On localhost port 8000 you have admin server in which you can check data in your local Datastore.
After that you can place phpinfo() in your .php file to check if you have 'gs' supported in "Registered PHP Streams" row.
Using "file_put_contents" instead of "fopen" fixed the problem for me.
Thanks
As the error suggests, the wrapper i.e. 'gs' is undefined.
Their are some build-in wrappers by php that can be used in fopen php function; for the custom wrappers i.e. 'gs' in your case, stream_wrapper_register php function can be used.
Reference links:
http://www.php.net/manual/en/wrappers.php
http://www.php.net/manual/en/function.stream-wrapper-register.php

Janrain's PHP-OpenID and Google/Yahoo

I'm using Janrain's PHP-OpenID 2.1.3, and I've managed to get it working with all the providers I have tried except for Google and Yahoo. The major difference here seems to be that Google and Yahoo, unlike most other providers, don't use a user-specific URL, but rather have the user discovery framework all on their end - which throws the default Janrain framework for a loop then it tries to begin the auth request.
From what I've seen it looks like it's probably the YADIS discovery that is throwing the error, which should be able to be bypassed since the discovery is on Google or Yahoo's end, but I'm not sure. This is all a big informal learning experience for me, and I haven't had any luck finding documentation that can help me on this one. Any tips would be greatly appreciated.
Edit: the specific problem I am having is that when the begin() function is called for the Google or Yahoo URL, I get a null return. This function is found in Auth/OpenID/Consumer.php for reference.
Ok, I finally got to fix the library... I explained everything here (you can also download the php-openid library after my changes).
I needed to do what Paul Tarjan suggested but, also, I needed to modify the Auth_OpenID_detectMathLibrary and add the static keyword to a lot of functions. After that It seems to work perfectly although it is not an ideal solution... I think that someone should rewrite the whole library in PHP 5...
I had the same problem on Windows XP. Fixed by activating curl extension. To do this uncomment in php.ini the line
extension=php_curl.dll
by removing the ; in front of it if any. Restart apache.
Also on windows to work properly you need to define Auth_OpenID_RAND_SOURCE as null since in windows you don't have a random source. You can do this by adding the line
define('Auth_OpenID_RAND_SOURCE', null);
in CryptUtil.php before the first code line
if(!defined('Auth_OpenID_RAND_SOURCE')){
Even if the curl is not enabled the API should work by using instead the Auth_Yadis_PlainHTTPFetcher to communicat via HTTP. In the case of Google and Yahoo you need https, so it only works if open_ssl is enabled (Auth_Yadis_PlainHTTPFetcher::supportsSSL must return true).
I had exactly the same problem and it took me nearly 2 hours to track the problem. Jan Rain's OpenId lib requires 'DOM or domxml PHP XML' (https://github.com/openid/php-openid) but it will fail silently when neither is available!
On my CentOS installation simple:
yum install php-xml
fixed the problem (I'm using this repo: http://blog.famillecollet.com/pages/Config-en).
Are you using the example RP? Can I suggest you submit a detailed bug at http://trac.openidenabled.com/trac/newticket?project=php-openid or a detailed enquiry via the mailing list.
The immediate_mode support indeed does work the libraries if implemented correctly. I (and others) would also be happy to help you on the OpenID IRC channel irc.reenode.net in #openid. My nickname is flaccid.
It's because you don't have curl support enabled enabled in php. Without this, it can't get https content. At least, that's what I discovered. When I tried to get yahoo or google, it failed with an error message "Authentication error; not a valid OpenID," but when I enable php_curl, it works properly.
Make sure your server has curl with https protocol enabled. This solved it for me.
see this thread.
Here is a quick script to test it out. Upload on your server then acccess it via your browser.
<?php
error_reporting(E_ALL);
// create curl resource
$myurl = 'https://<YOURACCOUNT>.myopenid.com';
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL, $myurl);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
if (empty($buffer))
{
print "Sorry, cannot access $myurl .<p>". curl_error($curl_handle);
}
else
{
print $buffer;
}
curl_close($curl_handle);
?>
If it returns " Protocol https not supported or disabled in libcurl" then you know what to do.
I tried it using my gmail account and it works but it leads to a 301 permanent rediret, which makes sense.
Another potential difference is that Google and Yahoo use HTTPS and if your PHP or SSL installation is misconfigured (perhaps missing CA certs) then your OpenID code will fail to establish an association or complete the check_authentication call.
But without error messages or logs, I can't really tell what type of failure you're looking at.
A couple of years too late, but this might be relevant for users using Janrains PHP OpenID 2.2.2 library on a Windows platform. I'm still on PHP 5.2.17.
My simple test, just to make sure the library was contacting Google was to use the examples/discover.php program, and pass Googles OpenID URL (https://www.google.com/accounts/o8/id).
As per the instructions, the standard steps are to enable GMP (uncomment extension=php_gmp.dll) and CURL (uncomment extension=php_curl.dll). XML should already be enabled.
You may also need to extract the package in contrib/google and make sure google_discovery.php and ca-bundle.crt are in Auth/OpenID.
The extra paranoid could start with examples/detect.php, to make sure they have things set up correctly. It is expected you'd pass all the tests except the Cryptographic Randomness test. For this, you'll need to add
define('Auth_OpenID_RAND_SOURCE', null);
to the top of examples/detect.php. And while you're there, add that to examples/consumer/common.php (since examples/discover.php uses it).
Now, even after all this, discovery for the Google OpenID URL was failing. I was getting CURL error (60): SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in the php error log.
In the Windows environment, you need a definition for the CURLOPT_CAINFO. For my quick test, I added curl_setopt($c, CURLOPT_CAINFO, dirname(__FILE__)."/../OpenID/ca-bundle.crt"); before the curl_exec() statements in Auth/Yadis/ParanoidHTTPFetcher.php.
This allowed the examples/discover.php to discover the services offered by the Google URL.
As a longer term solution for setting CURLOPT_CAINFO in Windows, you might like to refer to this StackOverflow answer so you can add a setting to your php.ini.

Categories