browscap / browscap-php

Officially supported Browscap for PHP
http://browscap.org/
MIT License
422 stars 82 forks source link

Can't retrieve file after fetching #206

Closed ghost closed 7 years ago

ghost commented 7 years ago
     29         try
     30         {
     31             $browscap_updater = new \BrowscapPHP\BrowscapUpdater();
     32             if($browscap_updater != null)
     33             {
     34                 echo "BrowscapUpdater instance created \n";
     35             }
     36             $wurfl_cache = new \WurflCache\Adapter\File(array('DIR' => __DIR__.'/composer/cache/'));
     37             if(isset($wurfl_cache))
     38             {
     39                 echo "WurflCache instance created \n";
     40             }
     41 
     42 
     43             $browscap_updater->setCache($wurfl_cache);
     44             if($browscap_updater->getCache() != null)
     45             {
     46                 echo "BrowscapUpdater cache set \n";
     47             }
     48         }
     49         catch(Exception $e)
     50         {
     51             echo 'Failed to create updater instance';
     52         }
     53         try
     54         {
     55             $browscap_updater->setClient(new \GuzzleHttp\Client());
     56             if($browscap_updater->getClient() != null)
     57             {
     58                 echo "BrowscapUpdater client set \n";
     59             }
     60         }
     61         catch(Exception $e)
     62         {
     63             echo 'Failed to attach guzzle client';
     64         }
     65         try
     66         {
     67             echo "Starting to fetch from browscap.org \n";
     68             $browscap_updater->setConnectTimeout(60);
     69             $browscap_updater->fetch('BrowscapINI', 'Full_PHP_BrowscapINI');
     70             echo "Finished fetching from browscap.org \n";
     71         }
     72         catch(Exception $e)
     73         {
     74             echo 'Could not fetch file';
     75         }

I'm trying to retrieve the file from the script and save it in a directory. After I run the script I cannot seem to find the browscap.ini file or where I am supposed to set the directory to place the file.

mimmi20 commented 7 years ago

If you don't change the current directory in your script, the file should be in the directory you have started your script.

ghost commented 7 years ago

@mimmi20 is the above script written correctly because I am not getting a BrowscapINI file or directory after executing the script.

mimmi20 commented 7 years ago

The script you posted looks fine.

ghost commented 7 years ago

Does the script get executed as a general user because they do not have permissions to write in that directory. Would the PSR log tell me anything and how would I go about setting that up?

mimmi20 commented 7 years ago

You need write access to the target directory. How to set up a logger you find in the readme.

ghost commented 7 years ago

@mimmi20 I finally figured out the problem and it was not at all what I expected. For some odd reason you cannot assign a caching method before fetching the data. I know it shouldn't impact any of the code on fetching but on my system if you remove lines 36-47 it works, If you keep lines 36-47 it does not fetch the file. Can you have someone else confirm my findings?

mimmi20 commented 7 years ago

If you have the same file already written into the cache, the screen does not fetch the file again.

ghost commented 7 years ago

There was never a browscap file in the directory before or after I tried the fetching method.