Error cURL 26 could not open file

So, I need help.

prePS - the code works, but does not work normally at boot.

Thus, the php code receives a file from the user and saves it on the cluster (4 nodes) as part of the tree.

so, simple code.

$user_file = get_full_filename_of_userfile_from_post_array('user_file'); $fin = fopen($user_file,'rb'); $fout1 = fopen(get_uniq_name('p1'),'wb'); $fout2 = fopen(get_uniq_name('p2'),'wb'); $fout3 = fopen(get_uniq_name('p3'),'wb'); while ($part = fread($fin)) { fwrite($fout1,get_1_part($part)); fwrite($fout2,get_2_part($part)); fwrite($fout3,get_3_part($part)); } fclose($fin); fclose($fout1); fclose($fout2); fclose($fout3); $location = get_random_nodes(3,$array_of_existing_nodes); foreach($location as $key => $node)//key 1..3 { if(is_local_node($node) { save_local_file(get_part_file_name($key)); } else { save_remote_file(get_part_file_name($key),$node); } } //delete tmp files, logs,...etc 

save_remote_file () - using cURL sends the POST method of the file, as in the docs

 $post_data = array( 'md5sum' => $md5sum, 'ctime' => $ctime, ..... 'file' => @.$upload_file_full_name, ); $ch = curl_init(); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Config::get('connect_curl_timeout')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); curl_setopt($ch, CURLOPT_URL, $URL.'/index.php'); curl_setopt($ch, CURLOPT_PORT, Config::get('NODES_PORT')); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 

So, during the test, I upload 14000 files, file per request, 10 requests per node (in parallel). php code, check the file and get a response, and then in the background save the file in the cluster. (yes, I know that it would be nice to create a daemon for saving - this is a task for the future)

SO, sometimes, there can be about 100 or even 200 php processes on a node in the background (use the php-fpm function)

 ignore_user_abort(true); set_time_limit(0); session_commit(); if(function_exists('fastcgi_finish_request')) fastcgi_finish_request(); 

A few calculations. 14000 files = 14000 * 3 = 42000 pieces, saving to random 3 out of 4, so 25% of the parts are saved locally, 75% recovery = 0.75 * 42000 = 31500 deleted pictures

during the test, I get about 100 errors on all nodes from the curl errno = 26 errer = could not open the file "## І_z lŠ…H" // this is strange because the name of the origin file is about 124 characters in the name. example

/var/vhosts/my.domains.com/www/process/r_5357bc33f3686_h1398258739.9968.758df087f8db9b340653ceb1abf160ae8512db03.chunk0.part2

before the cURL code, I added checks for file_exists ($ upload_file_full_name) and is_readable ($ upload_file_full_name); if not, write it down.

checks went well, but curl returns an error (100 times out of 31500 units)

add code, if error, wait 10 seconds, try againg, wait 10 seconds, try, wait 10 attempts.

always everything, if you first try with an error, all subsequent attempts with an error, too, but according to the logs, at the same time, another php processes something that saves other files, sends the part well through curl.

Therefore, I do not understand how I can find the cause and correct it.

0
source share

Source: https://habr.com/ru/post/969489/


All Articles