Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I would like to get your inputs on the "preferred" way of linking to dynamically generated excel files using PHP.

Using PHPExcel (or any other Excel writer for that matter) I have to generate a downloadable Excel file with PHP. The obvious method would be to create a link to that PHP file with a parameter such as

<a href="download.php?data=gdp">Download GDP figures</a>

However, for SEO purposes, the preferred method I think would be:

<a href="country_gdp.xls">Download GDP figures</a>

especially if advanced users (such as researchers) use the Google Search parameter filetype:xls in their searches.

Note that I am NOT an SEO expert and I don't have any evidence the latter is better. However I would assume the 2nd method would be more searchable than the first even by a small degree. The problem of course is that I don't know how to generate the Excel file dynamically using this 2nd method.

So is the 1st method acceptable and I'm just trying to complicate things? Or would you go for the 2nd method and have a workaround to call a PHP script to generate the excel file dynamically?

share|improve this question

migrated from stackoverflow.com Jul 18 '13 at 15:14

This question came from our site for professional and enthusiast programmers.

1  
I'm also not a SEO expert and don't know if the latter method is better. But you can achieve it using mod_rewrite –  hek2mgl Jul 18 '13 at 8:17
    
This is a programming question. I don't believe it should have been migrated. –  Homer6 Jul 18 '13 at 17:57
    
@Homer6 Me too. I believe my question is for a web programmer rather than a web administrator (or someone managing existing sites already) –  alds Jul 21 '13 at 16:17
    
@hek2mgl Yes I've thought about mod_rewrite. But I'm actually thinking how complex that may be since our site also contains other downloable files such as pds and videos –  alds Jul 21 '13 at 16:21

2 Answers 2

I'm going to take a wild guess and say that Google probably sees both documents correctly as a xls spreadsheet (provided that the Content-Type headers on the download.php url are set correctly).

However, generating the file will mean you'll have to decide where to store it. If you store it on the filesystem, you'll limit your ability to have more than one web server. If you store it in the database, you could be bloating your database a bit. If you store it on a CDN, there will be some latency while the file is propagated (from the time it's requested or generated).

But since you asked what my preferred method is, this is what I do. I don't like tying up the UI waiting for reports to generate. Where I work, some reports take several minutes to generate and tying them to the UI is error prone because if the user exits, it'll end the generation prematurely. Even though this may add complexity, I prefer to use RabbitMQ to decouple the events (ie. a generate report event from a user or a cron) from the work (ie. a process creating a report). RabbitMQ (or some similar message-bus architecture) also allows you to easily parallelize report generation (if there are a large number of them). Then, once the report has been generated, you can use one of the three storage methods (mentioned above) to store the generated report, safe in the knowledge that it's decoupled from your user's interaction. Caching even a little bit can help quite a bit (especially on a busy site). Users often don't mind a report to be a little stale. However, it very much depends on the nature of the report. If it's an operations report, it may be required to be up to the minute. In which case, there may be little room for pre-generating your reports. Also, if there are many different variables as inputs to the report, it may be infeasible to generate given the broad scope of the permutations.

Lastly, if the report generation is costly (in time, cpu, etc.), there is another hybrid option. You may be able to pre-summarize part of your report. If the latency-intensive part can be pre-calculated and the "up-to-the-minute" part of your report can use that information to quickly generate the report, then you may be able to directly generate the report from the user's request. With that, there are few more moving parts (such as invalidating the presummarization if the data changes). However, for records from the past (such as telemetry data), the data doesn't change. So, it's a great candidate for presummarization.

Sorry for the long response. Hope this helps.

share|improve this answer
    
potentially a +1 post. mod_rewrite should being mentioned –  hek2mgl Jul 18 '13 at 8:21
    
Thanks a lot for your informative answer. Though it didn't answer my question directly, it gave me a lot to think about. I have only considered the SEO aspect, but up to now haven't considered the performance and storage aspects. Our site's downloadable data and number of users are not (yet) that considerable, so message bus architectures (which I dont know anything about) and CDNs are not needed. But your suggestion of presummarization is interesting and can be explored with all our reports. Thanks! –  alds Jul 21 '13 at 16:09

This is a question in an Excel file generating speed. If your .xls is generated quickly - you may use the dynamic method. But it not preferrable, because you need to build your excel file every time the script called. The better way is to use cron script (if you need to update your xls) that generates your xls file and rewrites it in static location.

So I bet you will choose the second option with cron task generating the .xls file.

Have a nice day!

share|improve this answer
    
have you ever heard about mod_rewrite? Sorry for down-vote but your solution makes things too complicated –  hek2mgl Jul 18 '13 at 8:19
    
yes, of course I've heard of it. but I prefer to use NGinx and I do not need to use dynamic .xls generation because it is all about time. when you use cron tasks - you do not need to generate static xls file every time the script called. your web server just serving static xls file, which is more faster than generate it dynamically on each request –  Serge Velikanov Jul 18 '13 at 8:20
    
why not prerendering all your php pages? you could store them as HTML in filesystem –  hek2mgl Jul 18 '13 at 8:24
    
of course you can use memcached/redis for this kind of tasks. the filesystem is slower than RAM, you know this –  Serge Velikanov Jul 18 '13 at 8:26
1  
yes, you are perfectly right - it is all about particular tasks. –  Serge Velikanov Jul 18 '13 at 8:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.