With the help of reply from @Math remembered the Curl to create the POST.
So I started creating my own script PHP(upload_test.php
) where do I post my file(myfile_test.zip
) to the gravar.php
and keep the result in teste_results.txt
.
upload_test.php:
$user_id = rand( 1, 10 );
$local_file = '/my_dir/myfile_test.zip';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_VERBOSE, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)" );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_URL, 'http://localhost/gravar.php' );
$post_array = array(
"uploaded_file" => "@" . $local_file,
"function" => "upload",
"user_id" => "$user_id",
);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_array );
$response = curl_exec( $ch );
$myfile = fopen( "/my_dir/teste_results.txt", "a+" ) or die( "Unable to open file!" );
$txt = "\n=> AUTO_UPLOAD " . date( 'Y-m-d H:i:s' ) . "\n";
fwrite( $myfile, $txt );
fwrite( $myfile, "Fez upload? = " . $response . "\n" );
fwrite( $myfile, "\n" );
fflush( $myfile );
fclose( $myfile );
Curl source
On the side of gravar.php
get the file like this:
$uploaded = (object) $_FILES['uploaded_file'];
$file_name = $uploaded->name;
$file_tmp = $uploaded->tmp_name;
$file_type = $uploaded->type;
$file_size = $uploaded->size;
Then just add the execution line to the Crontab and I can create the lines you want to test my server load.
At the command line:
$ crontab -e
Insert next row and save: (10 in 10 minutes)
*/10 * * * * /usr/bin/php /var/www/html/my_dir/upload_test.php
Crontab source
You want to create a request via
file_get_contents ou curl
with a file upload together?– rray
Yes, you’ve lost someone who understands me :)
– Jorge B.