0

I'm thinking how to alter yourls to make new shorten urls faster. I don't really see where it is in the code, but when "yourls" is making new shorten url, it adds title to the database, so I assume that it has to open given url and parses it to get url. I don't need it and maybe it causes that short url creates slowly. I thought about making my own url shortener, but I am really out of time.

What do you think, is it anything that I can change in the yourls script, and where I can find in the code where it's searching it (i would just set title to "" constantly, cause this column can stay in the database for now).

zessx
  • 68,042
  • 28
  • 135
  • 158
Piotr Łużecki
  • 1,031
  • 4
  • 17
  • 33
  • Are you having slow performance issues? Setting just one database value to "" isn't going to help you much. Sounds like you're looking for a problem that doesn't exist. – jszobody Nov 14 '13 at 13:55
  • 1
    https://github.com/YOURLS/YOURLS/search?q=title&ref=cmdform led to https://github.com/YOURLS/YOURLS/blob/546057fc5ad1ea6158251679ab13b0d630da6ddd/includes/functions.php which has function yourls_insert_link_in_db( $url, $keyword, $title = '' ); but as @jszobody said, it wont solve your issues. Maybe filing an issue is the better way of solving your problem? https://github.com/YOURLS/YOURLS/issues – x29a Nov 14 '13 at 14:08
  • I have rails application with social buttons, which needs to have shorten url, so i generate shorten url in Controller to insert it into those social links. If i want to generate new one, yourls looks for title, and tries to open it, rails tries to generate new url... The problem is that i don't need title in the yourls and any http inspection. I didn't know github has such a great search function. – Piotr Łużecki Nov 14 '13 at 15:00

2 Answers2

1

If you just want a lightweight URL shortener, writing your own is probably the easiest way to go. Have a look at my super simple shortener script using DBM.

<?php

header('Content-Type: text/plain');

// Add url
if (isset($_GET['add'])) {
    $db = dba_open("/tmp/shortner.db", "c", "db4");
    if (!$db) trigger_error("dba_open failed", E_USER_ERROR);

    $key = substr(base_convert(md5($_GET['add']), 10, 36), 0, 5);
    dba_insert($key, $_GET['add'], $db);
    dba_close($db);

    echo "http://{$_SERVER['HTTP_HOST']}/$key";
    exit();
}

// Get url
$db = dba_open("/tmp/shortner.db", "r", "db4");
if (!$db) trigger_error("dba_open failed", E_USER_ERROR);

if (isset($_GET['key']) && dba_exists($_GET['key'], $db)) {
    $url = dba_fetch($_GET['key'], $db);
}
dba_close($db);

if (!isset($url)) {
    header("HTTP/1.0 404 Not Found");
    echo "Not found $_GET[key]";
    exit();
}

header("Location: $url");
echo $url;

With .htaccess

RewriteEngine On
RewriteRule ^(\w{5})$ /index.php?key=$1

You can easily add a hit counter if you need it, just before doing the direct. (In that case open the DB in 'w' mode).

Note that the key is based on a hash of the URL, so if the same URL is added again it just gets the same key (thus shortened URL).

Arnold Daniels
  • 16,516
  • 4
  • 53
  • 82
0

Without actually doing a desc on the query that you are talking about I don't think you can assume that it's the problem. You'd need to profile the whole script to find where it's running slowly.

ethrbunny
  • 10,379
  • 9
  • 69
  • 131
  • I should mention it earlier. It's rails applcation which tried to get shorten url in the controller, so when new url is made for webpage, it open this page, and tries to make the same url, which is looped. – Piotr Łużecki Nov 14 '13 at 15:01