<p>I think you have two options:</p>

<p><strong>1)</strong> Patch bitcoin-core and make <code>getrawmempoolentry</code> return the mempool transaction sorted after entry_date. There is boost multi index that would be capable to fast sort the mempool transaction (<a href="https://github.com/bitcoin/bitcoin/blob/master/src/txmempool.h#L303" rel="nofollow">https://github.com/bitcoin/bitcoin/blob/master/src/txmempool.h#L303</a>)</p>

<p><strong>2)</strong> You can try to improve your PHP sort speed. IMHO <code>Arsort</code> is not the best choice.</p>

CC BY-SA 3.0
2016-05-24T20:05:07.313Z
2016-05-24T20:05:07.313Z
Jonas Schnelli
<p>I'm trying to list out the results of <code>getrawmempool</code> by <em>newest transactions first</em>.</p>

<p><strong>Here's what I've got:</strong></p>

<p><code>getrawmempool</code> returns the memory pool in order of <em>transaction hash</em>, so I'm using PHP to sort it:</p>

<pre><code>&lt;?php
// Get an array of the memory pool transactions
$getrawmempool = $bitcoin-&gt;getrawmempool(true); // true = verbose

// Create a new array of "txid" =&gt; "time" (just so I can sort it)
foreach (array_keys($getrawmempool) as $txid) {
     $mempool[$tx] = $getrawmempool[$txid]['time'];
}

// Sort the new array
arsort($mempool);

// Print results
print_r($mempool);
?&gt;
</code></pre>

<p>Now, this isn't terribly slow, but sorting 10,000+ array values isn't terribly snappy.</p>

<p><strong>Questions:</strong></p>

<ul>
<li>Is there a way of getting the mempool in order of <em>newest first</em> from bitcoin-cli?</li>
<li>If not, is there a faster/better way of sorting the returned results?</li>
</ul>

<p>I'd like to play around with all the mempool transactions using PHP. So if I can get the mempool transactions in order along with all the verbose information about each one, that would be handy.</p>

<php><bitcoin-cli><getmemorypool>
Is there a way to get the memory pool in order of newest first?
inersha
# Is there a way to get the memory pool in order of newest first?

(Asked by: username_0 on 2016-05-24)

I'm trying to list out the results of `getrawmempool` by *newest transactions first*.

**Here's what I've got:**

`getrawmempool` returns the memory pool in order of *transaction hash*, so I'm using PHP to sort it:

```
<?php
// Get an array of the memory pool transactions
$getrawmempool = $bitcoin->getrawmempool(true); // true = verbose

// Create a new array of "txid" => "time" (just so I can sort it)
foreach (array_keys($getrawmempool) as $txid) {
     $mempool[$tx] = $getrawmempool[$txid]['time'];
}

// Sort the new array
arsort($mempool);

// Print results
print_r($mempool);
?>

```

Now, this isn't terribly slow, but sorting 10,000+ array values isn't terribly snappy.

**Questions:**

* Is there a way of getting the mempool in order of *newest first* from bitcoin-cli?
* If not, is there a faster/better way of sorting the returned results?

I'd like to play around with all the mempool transactions using PHP. So if I can get the mempool transactions in order along with all the verbose information about each one, that would be handy.

**Tags:** php, bitcoin-cli, getmemorypool


---

## 1 answers

### Answer by username_1 on 2016-05-24. Score: 2 | Accepted answer

I think you have two options:

**1)** Patch bitcoin-core and make `getrawmempoolentry` return the mempool transaction sorted after entry\_date. There is boost multi index that would be capable to fast sort the mempool transaction (<https://github.com/bitcoin/bitcoin/blob/master/src/txmempool.h#L303>)

**2)** You can try to improve your PHP sort speed. IMHO `Arsort` is not the best choice.


---

