我想知道是否有更有效的方法来提供大量链接重定向。背景:我的网站每天收到数以万计的用户,我们“深层链接”指向联属网站上的大量单独产品页面。
为了“隐藏”联属链接并将它们全部保存在一个位置,我目前从单个 PHP 文件提供我们所有的联属链接,例如,用户单击 mysite.com/go.php?id=1 并被带到商家网站上的页面,附有我们的附属 cookie,您可以在其中购买产品。我使用的代码如下:
<?php
$path = array(
‘1′ => ‘http://affiliatelink1.com’,
‘2′ => ‘http://affiliatelink2.com’,
‘3′ => ‘http://affiliatelink3.com’,
);
if (array_key_exists($_GET['id'], $path))
header(‘Location: ‘ .$path[$_GET['id']]);
?>
我遇到的问题是,我们每天都会链接到许多独特的产品,而 php 文件现在包含 11K+ 链接,并且每天都在增长。我已经注意到,通过 FTP 下载和编辑该文件需要很长时间,因为该文件的大小接近 2MB,而且在上传文件时,我们的网站上的链接不起作用。我也不知道服务器通过单个 php 文件提供这么多链接是否有好处 - 我还没有注意到任何速度减慢,但肯定可以看到这种情况发生。
所以我正在寻找另一种选择。我正在考虑简单地启动一个新的 .php 文件(例如 go2.php)来容纳更多链接,因为 go.php 太大了,但这似乎效率低下。我应该为此使用数据库吗?我也在运行 Wordpress,所以我担心过多使用 mySQL,而简单地使用 PHP 似乎更快,但同样,我不确定。
我的另一个选择是找到一种动态创建这些附属链接的方法,即创建另一个 PHP 文件,该文件将采用产品的 URL 并将我们的附属代码附加到其中,从而无需我手动更新包含所有这些链接的 php 文件,但是,如果我们每天通过这样的方式提供近 10 万次点击,我不确定对服务器的影响。
有什么想法吗?我使用的方法是否会导致我们的服务器必死无疑,或者我应该保持原样以提高性能?与我现在使用的简单 php 文件相比,使用数据库执行此操作或动态地在服务器上放置更多负载吗?任何帮助/建议将不胜感激!
I'm wondering if there's a more efficient way to serve a large number of link redirects. For background: my site receives tens of thousands of users a day, and we "deep link" to a large number of individual product pages on affiliate websites.
To "cloak" the affiliate links and keep them all in one place, I'm currently serving all our affiliate links from a single PHP file, e.g. a user clicks on mysite.com/go.php?id=1 and is taken to the page on the merchant's site, appended with our affiliate cookie, where you can buy the product. The code I'm using is as follows:
<?php
$path = array(
‘1′ => ‘http://affiliatelink1.com’,
‘2′ => ‘http://affiliatelink2.com’,
‘3′ => ‘http://affiliatelink3.com’,
);
if (array_key_exists($_GET['id'], $path))
header(‘Location: ‘ .$path[$_GET['id']]);
?>
The problem I'm having is that we link to lots of unique products every day and the php file now contains 11K+ links and is growing daily. I've already noticed it takes ages to simply download and edit the file via FTP, as it is nearly 2MB in size, and the links don't work on our site while the file is being uploaded. I also don't know if it's good for the server to serve that many links through a single php file - I haven't noticed any slowdowns yet, but can certainly see that happening.
So I'm looking for another option. I was thinking of simply starting a new .php file (e.g. go2.php) to house more links, since go.php is so large, but that seems inefficient. Should I be using a database for this instead? I'm running Wordpress too so I'm concerned about using mySQL too much, and simply doing it in PHP seems faster, but again, I'm not sure.
My other option is to find a way to dynamically create these affiliate links, i.e. create another PHP file that will take a product's URL and append our affiliate code to it, eliminating the need for me to manually update a php file with all these links, however I'm not sure about the impact on the server if we're serving nearly 100K clicks a day through something like this.
Any thoughts? Is the method I'm using spelling certain death for our server, or should I keep things as is for performance? Would doing this with a database or dynamically put more load on the server than the simple php file I'm using now? Any help/advice would be greatly appreciated!
发布评论
评论(1)
我要做的是:
更改 URL 格式以在其中包含产品名称以用于 SEO 目的,例如“my_new_product/1”之类的内容
然后使用 mod_rewrite 将该 url 映射到带有查询字符串的页面,例如:
然后创建一个包含以下字段的数据库表:
id(自动编号,唯一id)
url(重定向到的 url)
描述(在您的网站上创建 url 的文本)
然后,您可以构建一个简单的 CRUD 事物来轻松地保持这些内容最新,并让您的页面提供来自数据库的链接列表。
What I would do is the following:
Change the URL format to have the product name in it for SEO purposes, such as something like "my_new_product/1"
Then use mod_rewrite to map that url to a page with a query string such as:
Then create a database table containing the following fields:
id (autonumber, unique id)
url (the url to redirect to)
description (the text to make the url on your site)
Then, you can build a simple CRUD thing to keep those up to date easily and let your pages serve up the list of links from the DB.