Skip to content

Commit 8a218c9

Browse files
authored
Update README.md
1 parent fa350d5 commit 8a218c9

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,37 @@ For more information, see the [Google Documentation](https://cloud.google.com/vp
5757
1. Clone this repository:
5858
```bash
5959
git clone https://github.com/your-username/google-ip-prefix-diff-php.git
60-
2. Run the script in your PHP environment:
60+
2. Include the script in your Script:
6161
```bash
62-
php google_ip_prefix_diff.php
62+
$ip_prefixes = include 'google_ip_prefix_diff.php';
63+
64+
foreach ($ip_prefixes as $cidr) {
65+
echo $cidr . PHP_EOL;
66+
}
67+
68+
## Important Note: Avoid Direct Inclusion in Executed Scripts
69+
70+
This script downloads large JSON files and processes the differences in IP ranges, which can be **time-consuming and resource-intensive**. For this reason:
71+
72+
- **Do not include the script directly** in frequently executed scripts or APIs.
73+
- Implement a **local caching mechanism** to store the resulting CIDR ranges for repeated use.
74+
75+
### Suggested Basic Caching Logic
76+
77+
1. Run the script periodically (e.g., hourly) to generate the CIDR ranges:
78+
```bash
79+
php google_ip_prefix_diff.php > google_ip_ranges.txt
80+
2. Load the cached results in your executed scripts:
81+
```bash
82+
$ip_ranges = file('google_ip_ranges.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
83+
84+
foreach ($ip_ranges as $cidr) {
85+
echo $cidr . PHP_EOL;
86+
}
87+
3. Automate the caching process using a cron job or similar scheduling tool:
88+
```bash
89+
# Run the script daily at midnight to refresh the cache
90+
0 0 * * * /usr/bin/php /path/to/google_ip_prefix_diff.php > /path/to/cached_ip_ranges.txt
6391

6492
## Reference
6593
This is a PHP implementation of the Python script provided by Google:

0 commit comments

Comments
 (0)