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.
| Attachment | Size |
|---|---|
| stock.png | 21.83 KB |

#1
Probably your host is preventing opening sockets to remote sites due to security reasons.
#2
No, this is not the case, everything is running on localhost, and all ports are open.
#3
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
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
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.
#6
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
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
I redid the patch to have error checking and watchdog logging.
Fixed.
#9
Great, thanks.
#10
Automatically closed -- issue fixed for two weeks with no activity.