Serialized LOB design pattern in PHP

Stefanescu Mihai 8 months ago Design Patterns

Design pattern-ul Serialized LOB (Large Object) este un pattern menit pentru stocarea obiectelor binare mari (BLOB) in baza de date. In loc sa salvam datele BLOB direct in baza de date, acest pattern ne indeamna sa stocam aceste informatii intr-un sistem de storage diferit, de exemplu am putea sa le salvam pe disk sau in cloud, apoi in baza de date sa salvam doar o referinta catre acest BLOB. Astfel putem sa ne scalam sistemul mai bine si sa avem performante mai bune, BLOB-urile putand fi tratate separat fata de baza de date. Acest pattern, de asemenea ajuta la scaderea dimensiunii bazei de date.

Acest design pattern este destul de simplu si cel mai probabil l-ati implementat, intr-o forma sau alta, dar nu stiati cum se numeste.
Un simplu exemplu pentru acest design pattern presupunea indeplinirea urmatorilor pasi:

1.  Upload fisier binar (BLOB, de exemplu o imagine sau un video) pe un serviciu precum Amazon S3 (sau pe disk sau orice alt serviciu de cloud alegi).
2.  Din raspunsul de la S3 luam URL-ul si il salvam in baza noastra de date.
3.  Cand vrei sa folosesti acest fisier, poti lua informatiile de pe disk sau S3 (sau orice alt serviciu ai alege) on the fly.

Iata un simplu exemplu de cod:

/* Upload fisier binar (BLOB, de exemplu o imagine sau un video) pe un serviciu precum Amazon S3 (sau pe disk sau orice alt serviciu de cloud alegi).*/

$s3 = new S3Client([
    'version' => 'latest',
    'region'  => 'us-east-1',
    'credentials' => [
        'key'    => 'YOUR_KEY',
        'secret' => 'YOUR_SECRET',
    ],
]);

$result = $s3->putObject([
    'Bucket' => 'my-bucket',
    'Key'    => 'large-file.jpg',
    'Body'   => fopen('path/to/large-file.jpg', 'r'),
    'ACL'    => 'public-read',
]);

/* Din raspunsul de la S3 luam URL-ul si il salvam in baza noastra de date. */
$url = $result->get('ObjectURL');
$pdo = new PDO('mysql:host=localhost;dbname=mydb', 'user', 'password');
$stmt = $pdo->prepare("INSERT INTO files (url) VALUES (:url)");
$stmt->execute(['url' => $url]);

/* Cand vrei sa folosesti acest fisier, poti lua informatiile de pe disk sau S3 (sau orice alt serviciu ai alege) on the fly. */
$stmt = $pdo->prepare("SELECT url FROM files WHERE id = :id");
$stmt->execute(['id' => $file_id]);
$url = $stmt->fetchColumn();
$file_data = file_get_contents($url);

Acesta exemplu de cod este cat se poate de simplist, dar in functie de nevoile pe care le ai in proiectul tau, acest pattern poate fi usor adaptat pentru a ajunge sa implementezi cerinta de business pe care o ai.

Programator de ~8 ani, am lucrat la proiecte din mai multe industrstrii, de la eCommerce la telecomunicatii la automatizari. In acest timp am folosi diferite tehnologii, de la PHP, MySQL, PostgreSql, RabbitMq, Redis, Memcached si altele.


Get in touch
Pentru nelamuriri, dubii, comentarii si chestii de pe suflet ne putem auzi pe Discord, Reddit sau poti deschide o discutie noua pe forum

how to make money as a student from home # 5 months ago Promote holistic health products and make money with these affiliate marketing strategies passive income options for doctors in the usa part-time pharmacist jobs with flexible schedules Maximizing earnings with affiliate marketing for beauty and health bloggers
How to Earn Passive Income from Home # 5 months ago Asking questions are really nice thing if you are not understanding something fully, but this piece of writing presents good understanding even.
the role of medicine professionals in treating panic attacks # 5 months ago You actually make it seem really easy along with your presentation however I to find this topic to be really something that I feel I'd never understand. It seems too complicated and very wide for me. I'm looking forward for your subsequent submit, I'll attempt to get the cling of it!
prix du alonest au Maroc # 1 month ago First of all I want to say awesome blog! I had a quick question in which I'd like to ask if you do not mind. I was interested to find out how you center yourself and clear your mind prior to writing. I have had a tough time clearing my mind in getting my ideas out there. I do take pleasure in writing but it just seems like the first 10 to 15 minutes are lost simply just trying to figure out how to begin. Any recommendations or hints? Many thanks!
astonin 0.1 sans ordonnance en Espagne # 1 month ago Does your website have a contact page? I'm having problems locating it but, I'd like to shoot you an email. I've got some creative ideas for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it grow over time.
ivexterm 6 mg disponible sans ordonnance # 1 month ago Hello! Do you use Twitter? I'd like to follow you if that would be ok. I'm absolutely enjoying your blog and look forward to new posts.
compra de promethazine 25 mg en Perú # 1 month ago Asking questions are actually pleasant thing if you are not understanding anything totally, but this paragraph offers pleasant understanding even.
comprar clarithromycin en línea en Bélgica # 1 month ago I every time used to study post in news papers but now as I am a user of net thus from now I am using net for posts, thanks to web.
online apotheek voor lemoxin in België # 1 month ago Hello! I simply wish to offer you a huge thumbs up for the great info you've got right here on this post. I am returning to your web site for more soon.
comprar lebilon en Bolivia sin problemas # 1 month ago Today, while I was at work, my sister stole my apple ipad and tested to see if it can survive a 25 foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is entirely off topic but I had to share it with someone!
Verschreibungspflichtige Medikamentenpreise # 1 month ago Article writing is also a excitement, if you know then you can write otherwise it is difficult to write.
acheter acorspray en france # 1 month ago Hello there, I discovered your site by way of Google at the same time as searching for a comparable topic, your website got here up, it seems great. I have bookmarked it in my google bookmarks. Hello there, simply turned into aware of your weblog through Google, and found that it's truly informative. I am going to watch out for brussels. I'll be grateful for those who proceed this in future. A lot of other folks might be benefited out of your writing. Cheers!
sports betting script # 1 month ago Thanks a lot for sharing this with all folks you really understand what you're talking approximately! Bookmarked. Kindly also seek advice from my web site =). We may have a link exchange agreement between us
xabine disponible en Andorre # 1 month ago I like the valuable information you provide in your articles. I'll bookmark your weblog and check again here frequently. I am quite certain I will learn a lot of new stuff right here! Best of luck for the next!
mebendazole à prix compétitif en Espagne # 1 month ago I blog quite often and I genuinely thank you for your content. This article has truly peaked my interest. I'm going to book mark your blog and keep checking for new information about once per week. I subscribed to your RSS feed as well.
acheter du albendazole 400 mg en Espagne # 1 month ago I am really thankful to the owner of this web page who has shared this fantastic piece of writing at at this time.
Milo # 4 weeks ago I needed to thank you for this great read!! I certainly enjoyed every little bit of it. I have got you book-marked to look at new stuff you post…
Liza # 3 weeks ago Excellent blog you have here.. It's difficult to find high quality writing like yours these days. I truly appreciate individuals like you! Take care!!
Ervin # 3 weeks ago Does your blog have a contact page? I'm having problems locating it but, I'd like to send you an e-mail. I've got some ideas for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it expand over time.
Cornell # 3 weeks ago If some one wishes to be updated with most recent technologies after that he must be go to see this website and be up to date everyday.
Augustus # 3 weeks ago Hi there! I'm at work browsing your blog from my new iphone 3gs! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the outstanding work!
clarinex prijs in België # 3 weeks ago Howdy! Quick question that's entirely off topic. Do you know how to make your site mobile friendly? My website looks weird when browsing from my apple iphone. I'm trying to find a template or plugin that might be able to resolve this issue. If you have any recommendations, please share. Cheers!
progesterone 100 mg ohne Nebenwirkungen # 2 weeks ago Do you mind if I quote a few of your articles as long as I provide credit and sources back to your weblog? My blog is in the exact same area of interest as yours and my users would certainly benefit from a lot of the information you provide here. Please let me know if this ok with you. Many thanks!
Kan ik montelukast zonder recept krijgen? # 2 weeks ago Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a little bit, but other than that, this is excellent blog. A fantastic read. I'll certainly be back.
achat de zoltum de la marque Mylan # 1 week ago Howdy just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Chrome. I'm not sure if this is a formatting issue or something to do with internet browser compatibility but I thought I'd post to let you know. The design and style look great though! Hope you get the problem fixed soon. Cheers
Maude # 1 week ago Thanks for sharing your thoughts about design patterns. Regards
Kauf von Medikamenten in Italien online # 5 days ago The other day, while I was at work, my sister stole my apple ipad and tested to see if it can survive a thirty foot drop, just so she can be a youtube sensation. My iPad is now broken and she has 83 views. I know this is completely off topic but I had to share it with someone!
prijs van metrosa met voorschrift in Brussel # 5 days ago Nice blog right here! Additionally your web site quite a bit up fast! What web host are you the usage of? Can I get your affiliate hyperlink on your host? I wish my site loaded up as fast as yours lol
verkoop van amoxine in Frankrijk # 4 days ago Thank you for another informative web site. The place else could I am getting that kind of information written in such an ideal method? I have a mission that I am just now operating on, and I have been at the glance out for such info.
achat de pioglitazone # 4 days ago This is the right website for everyone who wishes to find out about this topic. You know a whole lot its almost tough to argue with you (not that I personally will need to…HaHa). You definitely put a new spin on a subject that's been written about for years. Wonderful stuff, just great!
vente libre de asacol en Belgique # 3 days ago Link exchange is nothing else however it is just placing the other person's website link on your page at appropriate place and other person will also do similar for you.
oracea 200 con receta médica # 2 days ago I don't even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you are going to a famous blogger if you are not already ;) Cheers!
avanafil 50 mg a prezzi accessibili a Eindhoven # 1 day ago My coder is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the costs. But he's tryiong none the less. I've been using Movable-type on a variety of websites for about a year and am concerned about switching to another platform. I have heard good things about blogengine.net. Is there a way I can import all my wordpress content into it? Any kind of help would be greatly appreciated!
où acheter mupirocin # 3 hours ago I'm truly enjoying the design and layout of your website. It's a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme? Great work!
Club-ul este dedicat membrilor si ofera access la mai multe zone ale website-ului.
Login Register

🔖 Bookmarks
✨ Pentru a sustine aceasta comunitate am sa te rog sa te autentifici sau sa te inregistrezi!

🌪️ Discord
Back to top
Folosim cookie-uri pentru a oferi functionalitatile critice ale aplicatiei Invata-Programare. Folosim cookie-uri si pentru a analiza traficul, pentru care e nevoie de consimtamantul dvs. explicit.