3v4l.org

run code in 300+ PHP versions simultaneously
<?php ##################################### # # CoSo cleaner. Delete posts older than X days # # Find me at awk_it_up@counter.social # # usage php ./coso_cleaner.php [--dry-run] # # Steps # # 1. Get your CoSo ID. # * Log into CoSo. # * Click your @name to view your profile. # * In the URL bar you will see the URL is now https://counter.social/web/accounts/XXXXXX. XXXXX is your CoSo ID. # * Copy that XXXXX value into the $coso_id variable below. # 2. Create a CoSo app. # * Edit your profile in CoSo and click the "Developement" link. # * Click the New Application button # * Create name (doesn't matter what) # * Select the Scopes: read & write and click the Submit button. This will bring you to the "Your Applications" page # * Click the name of your new application. # * Copy the "Your access token" value and paste it into the $coso_key variable below. # 3. Decide how many days of toots you want to keep and enter that value into the $age variable below. Default is 7. # 4. If you want to keep toots with specific tags regardless of age, enter the tags into the $ignore_tags variable below. Case insensitive, comma separated (no spaces), leave "" for none. # 5. If you want to keep specific toots regardless of age, enter the toot ID(s) into the $ignore_toots variable below. Case insensitive, comma separated (no spaces), leave "" for none. # 6. Run CoSo cleaner # * This is a PHP script so you must run it on a system with PHP installed # * The PHP curl module must also be installed # * Run: 'php coso_cleaner.php' or 'php ./coso_cleaner.php' on Linux systems # * Use the --dry-run switch to see what coso_cleaner WOULD delete, but not delete it # 7. Automate it # * On a system with a cron scheduler, use this entry to run it every day at 1AM # * 0 1 * * * /path/to/coso_cleaner/coso_cleaner.php >> /path/to/coso_cleaner/coso_cleaner.log # 8. Verify # * Check the coso_cleaner.log each day to see what it has deleted # #################################### $coso_key="82567dce7a829c44008c9d41bf65425a378fca5fd5548d4bc59aba09edbd6478"; # Your CoSo Key $coso_id="11036"; # Your CoSo ID $age = 6; # In days $ignore_tags = "cososec, pipepoem, cosopoetry, explicit"; # Comma separated, no spaces, leave "" for none. $ignore_toots =""; # Comma separated, no spaces, leave "" for none. ## Should not have to change anything below this $limit=40; $since_id=0; $url = "https://counter.social/api/v1/accounts/$coso_id/statuses?limit=$limit"; $statuses; $num_statuses; $max_status=0; $min_status=0; $status_array=[]; $range = 0; $min_date = 0; $dry_run = FALSE; $date = time(); $delete = 0; # Dry run? if ( isset($argv[1]) && $argv[1] == "--dry-run" ) { $dry_run = TRUE; print "Doing dry run (will not actually delete anything.\n"; } # Tags to ignore? if ( strlen($ignore_tags) > 0 ) { $ignore_tag_array = explode(",", $ignore_tags); print "Ignoring tags: $ignore_tags\n"; } # Toots to ignore? if ( strlen($ignore_toots) > 0 ) { $ignore_toot_array = explode(",", $ignore_toots); print "Ignoring toots: $ignore_toots\n"; } print "Run time: ".date("Y-M-d:H:i:s")."\n"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $coso_key")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_USERAGENT, 'CoSo Cleaner: awk_it_up@counter.social'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 0); $output = curl_exec($ch); curl_close($ch); $statuses = json_decode($output, TRUE); $num_statuses = $statuses[0]['account']['statuses_count']."\n"; # Find status id range $min_status = $statuses[0]['id']; print "Statuses found: $num_statuses\n"; # Get the max and min status IDs for ( $i = 0 ; $i < $num_statuses; $i += $limit ) { foreach ($statuses as $status ) { $delete = 1; if ( $max_status < $status['id'] ) { $max_status = $status['id']; } if ( $min_status > $status['id'] ) { $min_status = $status['id']; } # Ignore toots with specified IDs set if ( @count($ignore_toot_array) > 0) { foreach ($ignore_toot_array as $ignore_toot ) { if ( ($status['id'] == $ignore_toot) && $delete == 1 ) { $delete = 0; break; } else { $delete = 1; } } } # Ignore toots with specified tag set if ( count($status['tags']) > 0 && @count($ignore_tag_array) > 0 ) { foreach ($ignore_tag_array as $ignore_tag) { foreach ($status['tags'] as $status_tag ) { if ( $ignore_tag == $status_tag['name'] && $delete == 1 ) { $delete = 0; break 2; } else { $delete = 1; } } } } if ( $delete == 1 ) { $status_array[$status['id']]['id'] = $status['id']; $status_array[$status['id']]['date'] = $status['created_at']; $status_array[$status['id']]['content'] = $status['content']; } } # Reset curl to get the next batch o' statuses $url = "https://counter.social/api/v1/accounts/$coso_id/statuses?limit=$limit&max_id=$min_status"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $coso_key")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_USERAGENT, 'CoSo Cleaner: awk_it_up@counter.social'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 0); $output = curl_exec($ch); curl_close($ch); $statuses = json_decode($output, TRUE); } # Set up the date parameters $range =$age*86400; $today = time(); $min_date = $today - $range; # Set up the generic curl params again $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $coso_key")); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_USERAGENT, 'CoSo Cleaner: awk_it_up@counter.social'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 0); # Delete 'em! $delete = 0; foreach ($status_array as $status ) { if ( strtotime($status['date']) < $min_date ) { $delete++; if ( $dry_run ) { print "Dry run: Status ".$status['id']." on ".$status['date'].": \"".$status['content']."\" is in scope, but not actually being deleted due to dry run.\n\n\n"; } else { print "Deleting ".$status['id']." on ".$status['date'].": \"".$status['content']."\"\n\n\n"; curl_setopt($ch, CURLOPT_URL, "https://counter.social/api/v1/statuses/".$status['id']); curl_exec($ch); } } } print "Total affected toots: $delete.\n"; # Cleanup, bye bye. curl_close($ch);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.3.120.0040.01217.15
7.3.110.0060.01017.15
7.3.100.0030.00917.15
7.3.90.0000.01417.15
7.3.80.0030.01317.15
7.3.70.0060.01017.15
7.3.60.0000.01017.15
7.3.50.0090.00617.15
7.3.40.0100.00317.15
7.3.30.0070.00317.15
7.3.20.0040.01117.15
7.3.10.0060.00917.15
7.3.00.0090.00617.15
7.2.240.0040.01117.15
7.2.230.0030.00717.15
7.2.220.0030.01317.15
7.2.210.0130.00317.15
7.2.200.0060.00917.15
7.2.190.0090.00917.15
7.2.180.0070.01017.15
7.2.170.0040.01217.15
7.2.160.0030.01017.15
7.2.150.0090.00617.17
7.2.140.0030.01417.16
7.2.130.0070.01017.15
7.2.120.0060.01017.15
7.2.110.0330.00515.96
7.2.100.0260.00815.85
7.2.90.0280.00716.18
7.2.80.0270.01016.15
7.2.70.0270.00316.21
7.2.60.0270.00716.26
7.2.50.0210.01016.25
7.2.40.0260.01216.24
7.2.30.0350.00816.14
7.2.20.0280.00516.28
7.2.10.0270.01216.30
7.2.00.0300.00916.22
7.1.330.0030.01417.15
7.1.320.0060.01017.15
7.1.310.0060.00617.15
7.1.300.0100.00317.15
7.1.290.0100.00317.15
7.1.280.0000.01417.15
7.1.270.0030.01017.15
7.1.260.0070.00317.15
7.1.250.0080.00317.15
7.1.230.0530.00714.27
7.1.220.0520.00014.03
7.1.210.0530.00314.16
7.1.200.0360.01414.02
7.1.190.0500.00413.95
7.1.180.0500.01114.19
7.1.170.0400.00714.02
7.1.160.0500.00314.16
7.1.150.0410.01114.34
7.1.140.0320.01614.00
7.1.130.0560.00714.20
7.1.120.0430.00714.35
7.1.110.0450.01314.27
7.1.100.0510.00314.11
7.1.90.0440.00614.43
7.1.80.0450.00614.27
7.1.70.0430.01214.14
7.1.60.0540.01032.30
7.1.50.0550.00932.21
7.1.40.0460.01931.74
7.1.30.0460.01531.94
7.1.20.0500.01731.96
7.1.10.0540.00614.06
7.1.00.0480.00313.99
5.6.380.0170.00814.72

preferences:
38.8 ms | 400 KiB | 5 Q