Does not work with PHP 'allow_url_fopen = Off'

yhager - February 5, 2008 - 17:31
Project:Stock API
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

No matter what I do, the stockapi table is not populated with symbols, and thus nothing is fetched in cron run.

I configured the user quotes, and pressed 'save', and it got saved correctly into the {stock} table:

mysql> select * from stock;
+-----+----------------+
| uid | symbols        |
+-----+----------------+
|   1 | GOOG YHOO MSFT |
+-----+----------------+
1 row in set (0.00 sec)

But looking at the stockapi table I get

mysql> select * from stockapi;
Empty set (0.00 sec)

I also can't find anywhere in stock.module code where it calls stockapi_save(), so I see why this happens. There is nothing in the watchdog as well. Screenshot attached.

Please point me to what I am missing..

Thanks.

AttachmentSize
stock.png21.83 KB

#1

kbahey - February 5, 2008 - 19:07
Status:active» closed

Probably your host is preventing opening sockets to remote sites due to security reasons.

#2

yhager - February 7, 2008 - 08:37
Status:closed» active

No, this is not the case, everything is running on localhost, and all ports are open.

#3

yhager - February 7, 2008 - 09:27
Title:{stockapi} table is empty» Does not work with PHP 'allow_url_fopen = Off'
Project:Stock» Stock API
Version:5.x-1.0» 5.x-1.0
Priority:critical» normal
Status:active» needs review

This wasn't an issue with openning sockets, rather with calling file_get_contents with a URL parameter.
I've had 'allow_url_fopen' set to off, since this is less secure (see http://lwn.net/Articles/203904/).

I've solved this for now by setting it to On, but please consider using curl instead:

<?php
  $curl
= curl_init($url);
 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
 
$contents = curl_exec($curl);
 
curl_close($curl);
?>

#4

kbahey - February 7, 2008 - 17:02

Curl is not available in all installations.

There is also drupal_http_request().

If you have a working, tested and properly formatted patch that provides an option on whether to use file_get_contents, or curl, I will included.

Better make the option self discover what is available, and default to that too.

I will wait for the patch.

#5

yhager - February 8, 2008 - 13:07

Well, having drupal_http_request() for us, I see no reason to using something else.

I hope the patch is fine, it works for me.

AttachmentSize
yh.patch 864 bytes

#6

kbahey - February 8, 2008 - 17:18
Status:needs review» needs work

drupal_http_request() uses fsockopen() and fwrite()/fread(), which some PHP configurations may have blocked too.

Better have 2 options, the default would be drupal_http_request() and another selectable option (radio button), with the file_get_contents().

This way backward compatibility is maintained.

Curl can be left off for a future patch, if someone needs it.

So, please redo the patch with the two options above.

#7

yhager - February 10, 2008 - 16:09

drupal_http_request() is the way drupal core handles HTTP requests (see aggregator.module). I see no reason why the stockapi module should behave differently. I think it will just add redundant clutter to the UI of the stockapi if you were to add a selection box of the http request method.

As a matter of fact, I can't think of reason to build a setup that will block fsockopen(), but will allow openning a URL with fopen().

#8

kbahey - February 10, 2008 - 17:25
Version:5.x-1.0» 5.x-1.x-dev
Status:needs work» fixed

I redid the patch to have error checking and watchdog logging.

Fixed.

#9

yhager - February 10, 2008 - 17:35

Great, thanks.

#10

Anonymous (not verified) - February 24, 2008 - 17:41
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.