What is the recommended way to increase the memory limit in PHP using ini_set()?

When working with large datasets or processing intensive tasks in PHP, you may encounter memory limit errors. One way to increase the memory limit is by using the ini_set() function to dynamically set the memory_limit directive in PHP. This allows you to temporarily increase the memory limit for a specific script without having to modify the php.ini file.

// Set memory limit to 512MB
ini_set('memory_limit', '512M');