<commit_before><?php

/**
 * Usage:
 *  - Publish 100 5mb messages:
 *      php file_publish.php 100
 *  - Publish 1 5mb message:
 *      php file_publish.php
 *
 */

//suboptimal function to generate random content
function generate_random_content($bytes)
{
    $handle = @fopen("/dev/urandom", "rb");

    if ($handle) {
        $buffer = '';
        $len = 0;
        $max = $bytes;
        while($len < $max-1) {
            $buffer .= fgets($handle, $max-$len);
            $len = strlen($buffer);
        }
        fclose($handle);
    }

    return $buffer;
}

require_once(__DIR__ . '/../amqp.inc');
include(__DIR__ . '/config.php');

$exchange = 'file_exchange';
$queue = 'file_queue';

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();

$ch->queue_declare($queue, false, false, false, false);
$ch->exchange_declare($exchange, 'direct', false, false, false);
$ch->queue_bind($queue, $exchange);

$max = isset($argv[1]) ? (int) $argv[1] : 1;
$msg_size = 1024*1024*5+1
$msg = new AMQPMessage(generate_random_content($msg_size));<commit_msg>improves the file_publish script<commit_after><?php

/**
 * Usage:
 *  - Publish 100 5mb messages:
 *      php file_publish.php 100
 *  - Publish 1 5mb message:
 *      php file_publish.php
 *
 * NOTE: The script will take some time while it reads data from /dev/urandom
 */

//suboptimal function to generate random content
function generate_random_content($bytes)
{
    $handle = @fopen("/dev/urandom", "rb");

    if ($handle) {
        $buffer = '';
        $len = 0;
        $max = $bytes;
        while($len < $max-1) {
            $buffer .= fgets($handle, $max-$len);
            $len = strlen($buffer);
        }
        fclose($handle);
    }

    return $buffer;
}

require_once(__DIR__ . '/../amqp.inc');
include(__DIR__ . '/config.php');

$exchange = 'file_exchange';
$queue = 'file_queue';

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();

$ch->queue_declare($queue, false, false, false, false);
$ch->exchange_declare($exchange, 'direct', false, false, false);
$ch->queue_bind($queue, $exchange);

$max = isset($argv[1]) ? (int) $argv[1] : 1;
$msg_size = 1024*1024*5+1;
$msg_body = generate_random_content($msg_size);

$msg = new AMQPMessage($msg_body);
{'fraction_non_alphanumeric': 0.17747589833479405, 'fraction_numerical': 0.021034180543382998, 'mean_word_length': 3.21996303142329, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5800439', 'n_tokens_mistral': 840, 'n_tokens_neox': 781, 'n_words': 181}