ohffs

ohffs

Member Since 3 Years Ago

Glasgow

Experience Points 269,990
Experience Level 50

0 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 989
Lessons
Completed
Best Reply Awards 296
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

04 Mar
2 weeks ago

ohffs left a reply on Testing That The Log Record Has Been Written.

There is a fake logging package that might be of help - at least you will know the calls to write the log have happened :-)

08 Feb
1 month ago

ohffs left a reply on Defining Eloquent Function Return Type

I've taken to using them a bit as a quick 'aide-memoire'. It's handy to know if a method is going to return you a plain array or a collection for instance without having to read through the code as much. Some editors will also show you it on hovering over the method call too (PHPStorm, VSCode etc).

But I generally don't bother if either a) it's pretty obvious from the method name ('$user->isBanned()' or the like) or b) if I'm too lazy ;-) Inconsistancy ftw... ;-)

If you want to get 'fancy' then things like larastan/phpstan can use them to discover cases that you might have missed in your tests too.

06 Feb
1 month ago

ohffs left a reply on Showcase Site For Your Application, Laravel Or Wordpress?

I've been playing around with gridsome a bit - just deploying a little test side to netlify. It seems to work quite nicely - if you update your site and push to github, it's rebuilt and deployed by netlify without you having to do anything, And no server/hosting to think about :-)

02 Feb
1 month ago

ohffs left a reply on 5.8 Depreciated String And Array Helpers - Thoughts

I still haven't seen a very good reason for them being deprecated outside of a sense of 'purity' that you shouldn't add things into the global namespace. Which doesn't seem like a terribly strong argument when 10's of thousands of people are using them without it seemingly being an issue or causing collisions. I don't remember seeing very many threads on here complaining about 'str_random function collides with my own global function!!!!' :-/

I'm hoping that they at least update the docs to show using the Arr and Str classes. The pull request comment to deprecate them just says to use them as if everyone knows about them - but I'm guessing we're going to see a lot of people flooding the place with 'my codez have broken!!!' come 5.9 :-/. That's going to be fun... The only mention I can see of them is in this one odd place in the middle of the helper list which is more of a jarring exception than a help.

I can also imagine the number of videos (even on here) and around youtube and the web in general which are going to break - causing even more people to turn up here saying 'I followed the video here and it crashes!' :-/

I'm also hoping it's not going to be like the situation with the old-style http testing that just went missing around 5.5(?) and was moved into a package - that package doesn't seem to be in the docs any more so I keep having to google for it when I'm using a code-base that was heavy on them.

I wasn't a huge user of the helper functions (luckily - it turns out!) but pretty much every app I've got will have a few str_random's or array_except/only calls. So search & replace frenzy along with an extra use statement or two - here I come :-/. Fun times...

30 Jan
1 month ago

ohffs left a reply on Allowed Memory Size Of 134217728 Bytes Exhausted (tried To Allocate 1576960 Bytes)

This json stream package might help if you really need to process 40mb of JSON : https://github.com/halaxa/json-machine

29 Jan
1 month ago

ohffs left a reply on Laravel Docker Setup

Ontop of the serversforhackers link - the two courses by Bret Anderson on udemy are pretty good and only US$10 at the moment :

https://www.udemy.com/docker-mastery/

https://www.udemy.com/docker-swarm-mastery/

18 Jan
2 months ago

ohffs left a reply on Screencast Software

I've seen a lot of youtube/twitch coding tutorials using OBS

15 Jan
2 months ago

ohffs left a reply on When To Use Something Like Aws S3?

@SHADRIX - I've never used them - but I've heard of them quite a few times without any horror stories - up to you which one you use really. I guess whichever is cheaper/easier for your app :-)

ohffs left a reply on When To Use Something Like Aws S3?

If you're dealing with images, then something like cloudinary might be worth a look rather than spaces/S3. The free tier might be enough for you too. It'll let you upload the image and also take care of things like resizing & optimising the images. They will also tie in with the big CDN's so your images will get served up to your users from a nearby location rather than hitting your server - maybe on the other side of the world.

I think a lot of people default to S3 as there are good, well-tested, well-documented libraries for it and it's been around a long time. DO's spaces are a bit newer and a bit simpler.

07 Jan
2 months ago

ohffs left a reply on What Is A Good Way To Keep Track Of Cart Quantity Across Different Pages?

You could also use the browser's LocalStorage so store the cart. You'd have to do a little fancy footwork if you wanted to allow people to come back to the site with a different device and see their cart though.

01 Jan
2 months ago

ohffs left a reply on Audio To Code In Js Output

@SKYCODER - Glad to help - hope you have a great new year too :-)

ohffs left a reply on Audio To Code In Js Output

Wes Bos has a free tutorial on it over on youtube - that might help get your head around it :-)

31 Dec
2 months ago

ohffs left a reply on Is There A Shorthand To Schedule Commands To Be Queued?

Why not extract the logic of your export/ftp to it's own class - then just call that from both your artisan command and queued job?

29 Dec
2 months ago

ohffs left a reply on Can't Use Composer On Mac Mojave

@HJORTUR17 - Glad you got it working :-)

ohffs left a reply on Can't Use Composer On Mac Mojave

Is your composer file renamed to 'composer' or is it 'composer.phar'? Try and do an ls -l /path/to/your/composer file (or composer.phar) and make sure the permissions (first column) is something like -rwxr-xr-x. If you don't see the x's then do a `chmod +x /path/to/your/composer' and try running composer again.

28 Dec
2 months ago

ohffs left a reply on Under Docker Error Call To Undefined Function Intervention\Image\Gd\imagecreatefromjpeg

@MSTDMSTD - It looks like that should only happen if you're loading a webp file (from a quick look at the sourcecode). There is a stackoverflow answer that might help get webp installed which might get the error to go away though ;-)

ohffs left a reply on Under Docker Error Call To Undefined Function Intervention\Image\Gd\imagecreatefromjpeg

I've got a docker image with GD installed - try this part :

FROM php:7.2-apache

RUN apt-get update && \
    apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev libgmp-dev libldap2-dev netcat sqlite3 libsqlite3-dev && \
    docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-install gd pdo pdo_mysql pdo_sqlite zip gmp bcmath pcntl ldap sysvmsg exif \
&& a2enmod rewrite

If that doesn't help - try doing a call to phpinfo() and see if GD is showing has having jpeg support - I seem to remember it can be a bit picky about the order you do things in :-/

26 Dec
2 months ago

ohffs left a reply on Yarn.lock Is Causing Npm Run Dev To Fail

@bobbybouwmann this hit me recently too in slightly different circumstances. If mix sees a yarn.lock file it will try and run yarn - even if it's not installed (as far as I can tell). It hit me doing a CI build after I'd been debugging npm issues (again) and had used yarn as a test - then inside the CI build it didn't have yarn and started to crash.

I think some part of doing a laravel new triggers a yarn.lock file to be created too - so I'd guess it's related to the way mix works. I meant to put an issue on the mix github but then started drinking & eating all the food on earth in the run up to xmas ;-)

25 Dec
2 months ago

ohffs left a reply on How To Compact + Uglify + Strip Unused CSS And JS For Production Deploys?

If you're using mix v4 I think you can pass an option to 'terser' to mangle all the js/css. Might be as easy as :

mix.options({
  terser: {
    mangle: true
  }
});
24 Dec
2 months ago

ohffs left a reply on Using Redis Throttling For Sending Queued E-mails

When you're using throttle I seem to remember you're supposed to pass it the name of a new, temporary 'queue' - rather than the one you're trying to throttle? So in this case it would be something like :

Redis::throttle('throttled.send.newletter')->....

I might be wrong though :-) If you're chunking your results you might need to make a 'throttled' per-job too - like :

$jobId = Redis::incr('throttles');
Redis::throttle("throttled.{$jobId}.send.newsletter")->...

As I say - I might be 100% wrong though :-)

22 Dec
3 months ago

ohffs left a reply on Return Api() !!!!

I guess someone's added a helper function that is just a shorthand for return response()->json([]);

ohffs left a reply on Vue Js, Restrict Length Of <input />

Would a simple filter do? Or you could use a watcher on the value and just trim the length? Either that or bind the value and input events separately and do it in the event handler I guess.

21 Dec
3 months ago

ohffs left a reply on Are Long Waiting Times A Must Or Bad Development?

This comes back to mind... ;-)

20 Dec
3 months ago

ohffs left a reply on How To Prevent Revealing Used Technologies Name And Versions

Does running your js stuff through terser help? I haven't tried it with mix v4 yet - but it's something like :

mix.options({
    terser: {mangle: true},
});

maybe ;-)

ohffs left a reply on Get Image/video Metadata From Stream

Can you post some of your code here so if anyone else is trying to do the same thing they will be able to see how to do it? :-)

19 Dec
3 months ago

ohffs left a reply on Add Up/Down Vote Instead Of Best Reply

@CMDOBUENO - > What this is about, is people that barely understand what they are doing, thinking they know the right way, spreading a plague of misinformation.

I don't think I've ever heard the internet described so well ;-)

ohffs left a reply on Add Up/Down Vote Instead Of Best Reply

Maybe something like allowing the thread creator to pick the best reply (as now) but also a 'community best reply' award that was the most liked/favourited/upvoted one?

I also dislike the idea of downvoting as it often leads to 'in crowds' just downvoting people they don't like (see Reddit for instance).

There's also the issue of things that were 'best' when they were awarded now being out of date - I quite often see people replying to old threads saying they've tried some advice that was for Laravel 4.x or something and not understanding why they can't see the files mentioned. How you go about that without relying on people manually marking them is another matter though - some advice is (relatively) timeless - some goes out of date in a few weeks (javascript - I'm looking at you... ;-)

It's a hard problem to solve I think - look at Stackoverflow for instance - they've been pretty much dedicated to the issue for years and it's still full of out-dated 'best replies' that are wildly out of date or just wrong.

ohffs left a reply on Purpose Of $commands In Kernel.php (Task Scheduling)

It was used in previous releases (I think until 5.5 maybe) - then the framework added the ability to automagically find the commands. It's still there partly for backwards compatibility and also handy if you want to put your commands in a different directory.

As for output - it'll only print something to the console if the command has something like $this->info('Starting...') inside it.

17 Dec
3 months ago

ohffs left a reply on If You See A Post Again. Laravel Counts It As A View :)

@AURAWINDSURFING - I think they mean the view count for threads on the forum - not 'laravel' :: shrugs ::

ohffs left a reply on Low Request Per Second With Laravel, Docker, And AWS

You could also try using something like blackfire - there's a free trial which might be enough to get you narrowing down the problem.

ohffs left a reply on Low Request Per Second With Laravel, Docker, And AWS

If you really can't bring up a test copy for whatever reason, can you install something like php-spx - it might help you narrow down where the time is being spent - but it'll only show you it for the php part - if the problem is elsewhere (docker/aws/nginx/whatever) you'll still be in the dark :-/

ohffs left a reply on Low Request Per Second With Laravel, Docker, And AWS

@BEERBUDDHA - I've edited my reply with a few other pointers :-)

ohffs left a reply on Low Request Per Second With Laravel, Docker, And AWS

@BEERBUDDHA - I think what @markotitel and I are suggesting is to try it (just as a quick test) on another environment (outside of docker) just to check if docker is contributing to the problem. Not to replace your whole production setup :-) The reason I was suggesting running it outside of AWS was again, just to check another possible reason it could be going slow. AWS is much more complicated animal than, say, Digital Ocean - there are all sorts of things that can be combined that could be having a side-effect.

If you add a route to your code that does something like :

Route::get('/whatever', function () {
    phpinfo();
});

then it should tell you if opcache is enabled and what the settings are (there is a section labelled 'Zend OPcache'). Maybe also start up another container on a different port using the base php image. I usually use php:7.2-apache so I don't have to bother setting up fpm/nginx as well for instance. Just do a laravel new test-project and build it inside the container and see how many requests it can handle. Something like this should do it :

FROM php:7.2-apache

RUN apt-get update && \
    apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev libgmp-dev libldap2-dev netcat sqlite3 libsqlite3-dev && \
    docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-install gd pdo pdo_mysql pdo_sqlite zip gmp bcmath pcntl sysvmsg exif \
    && a2enmod rewrite

COPY vhost.conf /etc/apache2/sites-available/000-default.conf

EXPOSE 80

COPY . /var/www/html

RUN chown -R www-data:www-data /var/www/html/storage
RUN chown -R www-data:www-data /var/www/html/bootstrap/cache

CMD ["apache2-foreground"]
// vhost.conf
<VirtualHost *:80>
    DocumentRoot /var/www/html/public

    <Directory "/var/www/html/public">
        AllowOverride all
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
15 Dec
3 months ago

ohffs left a reply on Low Request Per Second With Laravel, Docker, And AWS

I was just meaning to try it on bare metal as a quick test - if that was possible :-) Just to rule out that docker was the issue :-) Docker 'nat' in particular can hit you with a 50% performance overhead :-/ We're moving towards docker swarm/kubernetes too so I've been digging into the networking quite a lot recently :-) I'm not an AWS user so can't offer any advice on that side of things sadly :-/

I don't know if you can try it - but if you have a swarm available - see if you can deploy multiple copies of the app and let something like traefik take care of wiring it all up so requests are split over multiple containers - that's what we're doing just now. But I'm really not sure that would help if you're seeing 100% cpu load across all your cores anyway. In my little raspberry pi test I could only get the 4 ARM cores to max-out at about 80%.

Your app isn't logging a lot of stuff, is it? Or using disk for session/cache? A lot of disk I/O could slow things down a lot too :-/

ohffs left a reply on Low Request Per Second With Laravel, Docker, And AWS

As a quick test - I just did a basic benchmark against a little laravel app I have running on a raspberry pi (it uses Redis/Sqlite-on-disk and performs an API lookup to another service on localhost) and I can get 100req/sec with 100 concurrent users - so with your hardware you should be able to handle way, way more than that. It's very odd :-/ Is it possible to try your app on another server outside of a docker container? Some of dockers network modes can have a very big impact on network performance :-/

ohffs left a reply on Low Request Per Second With Laravel, Docker, And AWS

I think you should be able to handle a lot more traffic than that given the box you have. Does your docker image have xdebug enabled, maybe? Is the DB running on the same box as the application?

It might be worth looking through the deployment guide and Chris's other video series on scaling with forge might give you some tips (he has a paid one too).

Without seeing exactly what your app does, how it's configured etc - nothing else is coming to mind I'm afraid :-/

13 Dec
3 months ago

ohffs left a reply on What's The Best Way To Go About Caching User Generated Content?

@ZENITH2012 - No worries at all :-) Enjoy digging more into laravel and maybe vue - it's a very productive combination when you need it down the line :-)

09 Dec
3 months ago

ohffs left a reply on Get Image/video Metadata From Stream

@CGUY - I think it would have to read the whole file through memory - yeah. I'm not sure if there's a better way without storing the file temporarily I'm afraid. Maybe someone else will chip in though :-)

ohffs left a reply on Get Image/video Metadata From Stream

Your best option might be to run ffprobe against the file once it has finished being ::put() to the remote server. I think mpeg streams have to be read as a whole (or rather the stream info can be anywhere in the file) to figure out what they contain - so I don't think you could just use a chunk or stream to get the info - I might be very wrong though! I have vague memories of trying to do this a few years ago by just storing the first few kb/mb of the file - but it never worked :-/

ohffs left a reply on What's The Best Way To Go About Caching User Generated Content?

@CORBIN - Redis is pretty efficient - but it'll depend on your own data I'm afraid - try building up a few thousand fake threads with a few hundred replies each and storing them in your redis cache and see how it goes. You can also use Redis's expireat to automatically clear data out of the cache after a certain amount of time if no-one has looked at them (you need to re-set the expire time if someone views it again of course) - that way threads that have faded from the 'front page' (in what-ever sense) don't take up memory. You'll have to figure out what makes sense for your site again though - maybe you only trigger caching on 'hot'/'popular' threads if you're really constrained.

But when you're thinking about caching pretty much text content - remember that the complete works of Shakespeare as html only take up about 6mb, so it's surprising how much you can cache in a small amount of RAM :-)

In my case I just cached a data structure that the JS was expecting to get so there was no processing to do - but you could take it a step further and render out the html and cache that.

If I were you I'd see how you get on without caching at all though - mysql/postgres etc are pretty efficient themselves and will cache a lot of queries for you, so you might not need all the complexity. If you've got your actual app running on one small box, and the DB server on another you'd be really surprised at how much traffic you can handle without doing much work :-)

But try creating a decent amount of fake data and then see what something like apache ab says when running with lots of simultaneous page-views. There are more thorough load testing tools like gatling too which can simulate 1000's of users viewing, posting, clicking around etc.

08 Dec
3 months ago

ohffs left a reply on What's The Best Way To Go About Caching User Generated Content?

@zenith2012 if it failed I just popped up an error as per usual on the page using JS along with a little 'retry?' button (pretty much just the .catch() block in axios). Not exactly the best UX as if they left the page before it happened they wouldn't know - but it wasn't really that critical. To me anyway ;-)

I actually just this week implemented much the same thing for a different site but with a much nicer system using the new laravel websockets package and vue-toasted that will alert them of a problem even if they've left the page. It's fairly easy to do now thankfully! :-)

ohffs left a reply on What's The Best Way To Go About Caching User Generated Content?

You might find this post on dev.to useful. They also list their stack on their github page which might give you some ideas.

For a site I had to look after where there were a lot of posts/channels/threads etc - I eventually made it so when a user posted a reply to a thread it was inserted into the UI right away via JS so the user got immediate feedback - and sent an ajax post off to the server which actually saved it to the DB and updated a cached version of the thread via little background job. Seemed to work ok and cut down the database load quite a lot.

It's the kind of thing you have to try out for a particular scenario and see what cost/speed/effort trade-offs you can make. Maybe for something like a forum/thread/replies set-up it makes more sense to use something like MongoDB and just insert the reply into the post object for instance. Sometimes it might be better to cache using sharded redis if you're really busy. As usual - 'it depends' :-)

07 Dec
3 months ago

ohffs left a reply on Secure Links In Laravel

'Signed URL's' might be what you're after : https://laravel.com/docs/5.7/urls#signed-urls

ohffs left a reply on Add Playing Time To Episode List?

@jlrdw it looks like this to me - no playing time : https://imgur.com/a/BCO6zOG

06 Dec
3 months ago

ohffs started a new conversation Add Playing Time To Episode List?

Is there any chance the playing time could be added to the episode list? It's not a big deal - but it's handy when you see new videos to be able to quickly think 'oh, that's 10 minutes - I'll watch that while waiting on pasta cooking' or 'oh, that's 40 minutes of watching - I'll watch that while I wait on that curry cooking' :-)

And yes - I do a lot of video watching while cooking ;-)

ohffs left a reply on Does This Email API Exists? Laravel > Json > External Email Service

Something like mailgun or mailchimp might be what you're after?

05 Dec
3 months ago

ohffs started a new conversation Laravel Websockets

This looks like it might be very useful when you cant or don't want to use Pusher and avoid the hassles of the node echo-server :

https://murze.be/introducing-laravel-websockets-an-easy-to-use-websocket-server-implemented-in-php#pair-programming-is-fun

26 Nov
3 months ago

ohffs left a reply on Send Email Alert At 90% Usage Only Once (best Practise?)

@DR.BOB - no worries - hope you get it working ok :-)

24 Nov
3 months ago

ohffs left a reply on Send Email Alert At 90% Usage Only Once (best Practise?)

@DR.BOB - I think @cronix means that your event listener would do something like :

if ($user->isOverSomeLimit()) {
  $user->sendSomeWarning();
}
User.php:
public function sendSomeWarning()
{
  if ($this->hasBeenRecentlyNotified()) {
    return;
  }
  $this->notify(...);
  $this->recordNotification();
}

The hasBeenRecentlyNotified and recordNotification methods could either look up/update a DB table - or you could use Redis and use it's 'expire'/ttl facility as a kind of 'expiring flag', eg :

// hasBeenRecentlyNotified()
return $redis->exists("userwarned:{$this->id}");

// recordNotification()
$ttl = 60 * 60 * 24; // ie, one day in seconds
$redis->set("userwarned:{$this->id}", true));
$redis->expire("userwarned:{$this->id}",$ttl);

ohffs started a new conversation Resume/multipart S3 File Storage?

I've got a little app that copies video files from on raspberry pi to another via wifi using an S3-compatible server (minio). The wifi is pretty erratic sadly, so sometimes the connection drops.

At the moment the code that does the Storage::put is wrapped in a try/catch that retries upto three times before giving up. But each retry is starting the upload from scratch - so what I'd like to do is have it try and resume the upload rather than start again to increase the chance of it completing each try. I can see the AWS S3 SDK supports it - but I can't see anything about accessing it via the Laravel Storage facility.

Does anyone have any pointers? If it's not exposed I'll just drop down to using the AWS code itself - but if I'm just missing a little flag or something it'd be nice to stick with the existing Storage:: methods :-)