Limit the size of files to be unzipped using shell_exec

Currently, I am utilizing the following code to download a zip file from an external server that contains more than 1,000 images. The process of downloading and creating/copying the source zip file onto my server is successful, but for some reason, the code stops executing at this point. The expected output from the if else statement below does not appear.

Initially, I had set CURLOPT_TIMEOUT to 240, however, this proved to be insufficient as it would result in a curl timeout error. Given that the zip file is close to 100MB in size, I estimated that the process would take around 15 minutes to complete. Hence, I adjusted CURLOPT_TIMEOUT to 1200 considering the varying sizes of the source zip file on a daily basis.

Any insights on why the code ceases to function? Are there any specific settings that require modification?

$source_photos_file = 'source_photos_file.zip';
$curl = curl_init();
$destination_photos_file = fopen($_SERVER['DOCUMENT_ROOT'].'/files/photos.zip', 'w');

curl_setopt($curl, CURLOPT_URL, FTP_URL.$source_photos_file); #input
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_TIMEOUT, 1200);
curl_setopt($curl, CURLOPT_FILE, $destination_photos_file); #output

if (curl_exec($curl) === false)
{
    echo '<p>Curl error: ' .curl_error($curl). ' - error # '.curl_errno($curl).'</p>';
}
else
{
    echo '<p>Execution completed without any errors</p>';
}

curl_close($curl);
fclose($destination_photos_file);

$photos_unzip_result = shell_exec('unzip -P password '.$_SERVER['DOCUMENT_ROOT'].'/files/photos.zip -d '.$_SERVER['DOCUMENT_ROOT'].'/files/pics_test/');

Answer №1

It is essential to carefully analyze your actions in this situation. In addition to basic troubleshooting such as error logging at the highest level and monitoring the error log, pay attention to what you are actually doing:

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);    

By explicitly instructing curl to return the download, you are essentially duplicating it in memory. Consider disabling this option, especially since you have already specified an output file.

While I cannot guarantee that this will resolve your issue, I hope this advice proves helpful. Remember to implement thorough error logging and provide specific information on notices, warnings, and errors.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to improve the speed of MySQL INSERT queries

I am currently running a program that collects information from multiple merchants. For each request received from a merchant, my program executes an INSERT query: INSERT INTO `good` (id, code, merchant, netcost, ip) VALUES ('', 'GC8958&ap ...

Creating custom image sizes for different post types in WordPress

I recently created a WordPress site with two slider-bars and various sections containing images of different resolutions. Now I am looking to use the add_image_size function to crop these images for specific tasks, but I'm unsure how to properly link ...

Error parsing data in Ajax POST request

I'm currently working on developing a web chat room. I encountered an issue when sending a POST request to the server using the following code snippet: var line_count = 0; $.ajax({ type: 'POST', url: '../scripts/engine.php&apo ...

If the cursor hovers over an image, the onmouseover function does not work properly

Currently, I am developing a PHP page to display data from a database in a tabular format. Each column in the table represents an 'ATC Station'. When active, additional data is displayed upon hovering over the cell. Everything was running smooth ...

PHP: Ways to combine the elements of this array?

Here is the code snippet I am working with: $arr = array($check); After executing this line: echo "<pre>"; die(print_r($arr)); The result displayed in Firebug is: <pre>Array ( [0] => Array ( [0] = ...

Create a custom Magento module to retrieve information from the backend

I am facing an issue with retrieving data from the backend to display it in my controller. For instance, consider this module: In config.xml, I will configure a routers for the controllers <frontend> <routers> <custompay> ...

The XML data format used to make a query on the OCS service in Nextcloud

Looking for a way to obtain a direct download link to a Netcloud file. Instructions: To get a direct link: POST /ocs/v2.php/apps/dav/api/v1/direct Include the fileId in the body (ex: fileId=42). I am trying to make a POST request using Nodes.js. What s ...

Issues with the functionality of the contact form

I have recently purchased a new template that comes with a contact form featuring ajax and validation. I have tried to implement my script, but it doesn't seem to be working. I suspect there might be an issue on the server-side with my script. Can any ...

Implementing Spam Prevention in the Php Contact Form

Can anyone provide assistance in resolving this issue? I am attempting to integrate this code into my contact form to prevent spam emails, but it is not functioning as expected. Html: Access code: <input type="text" name="code" /><br /> Kin ...

Display data from a PHP array in a JavaScript alert box

Within my Wordpress registration form, I am attempting to display the $error array in an alert message. I have experimented with using console.log(), but it does not show any output. Even when using JSON.stringify(), the alert only displays the word: true ...

Preventing the override of product description fields in a specific language through a webservice

My goal is to synchronize product data between two Prestashop websites using a webservice. Specifically, I want the description of a product on the destination website to match the description of the same product on the source website after synchronization ...

Transforming hexadecimal color codes into spans

I've been experimenting with regex patterns to transform hexadecimal colors into spans. Take this example: #FF0000Hello#00FF00There <span style="color: #FF0000">Hello</span><span style="color: #00FF00">There</span> ...

PHP not delivering a variable via AJAX

I've noticed that there are similar questions on this platform, but I've spent my entire day researching and fixing bugs to figure out why my ajax code doesn't return a response from the php file. All I need is for it to notify me when a use ...

Tips on sending asynchronous requests to a PHP page using jQuery AJAX

As a newcomer to web development, I am working on creating a social networking website for a college project. One feature I want to implement is updating the message count in the menu every time there is a new message in the database for the user (similar ...

Tips for effectively redirecting traffic to another website

Is there a way to redirect someone from a page URL like example.com/2458/233 to example2.com/2458/233? The first URL contains only a file that redirects to the other domain. Can anybody provide instructions on how to achieve this process? To clarify furt ...

Is this jQuery script not functioning properly?

I came across this code on jsfiddle, and I really want to incorporate it into my PHP file. However, when I tried to do so, it didn't work even though I simply copied and pasted the code without making any changes. Here is my code: <!DOCTYPE html& ...

Utilizing a server for seamless communication between a mobile device and a website

Exploring a simple setup idea here: Imagine having a mobile app with a page that contains 4 lines of content (utilizing phonegap for development). The plan is to have a web page where data for those 4 lines can be inputted. Once the information is submitt ...

Tips for utilizing mysql_connect(...) on a web hosting platform

Recently, I signed up for a web hosting service and have just started learning PHP and MySQL. I came across this video tutorial https://www.youtube.com/watch?v=gvGb5Z0yMFY which demonstrates how to add a row to a table. In my MySQL database, I have a table ...

Show a picture without specifying its file location

Looking for Suggestions on a New Title I am interested in using a script as the source attribute for an image, like this : <img src="img.js"/> Note: I am open to using any programming language, whether it be javascript or php. Here is what my fol ...

Protecting User Input: Safeguarding Against SQL Injection with mysql_real_escape_string

When users input data that ends up in a MySQL table, I always make sure to run it through the mysql_real_escape_string() function as recommended by PHP.net and various forum members. However, I really have no idea what this function does internally. What ...