Need PHP or Java code to use multiple Internet connections.

I have a machine with a Linux CentOS distribution that has more than one Internet connection available at a time.

I am trying to write PHP code that will do the following:

  • Make an HTTP request to a specific URL "for example google.com", but through a specific Internet connection.
  • Perform the above for several Internet connections at the same time (this means that several processes will be executed, each of which will have HTTP requests through a specific connection).

Note that internet connections are ppp0, ppp1 and ppp2.

Here is the result of "ifconfig":

eth0      Link encap:Ethernet  HWaddr 00:23:7D:3B:04:26
          inet addr:86.111.198.9  Bcast:86.111.198.15  Mask:255.255.255.240
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:33511 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24728 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3144233 (2.9 MiB)  TX bytes:3930225 (3.7 MiB)
          Interrupt:185 Memory:f8000000-f8012100

eth1      Link encap:Ethernet  HWaddr 00:23:7D:3B:04:1E
          inet addr:192.168.1.64  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7570 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6730 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:553439 (540.4 KiB)  TX bytes:463989 (453.1 KiB)
          Interrupt:193 Memory:fa000000-fa012100

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:95 errors:0 dropped:0 overruns:0 frame:0
          TX packets:95 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:14908 (14.5 KiB)  TX bytes:14908 (14.5 KiB)

ppp0      Link encap:Point-to-Point Protocol
          inet addr:78.93.176.35  P-t-P:212.93.193.40  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1442  Metric:1
          RX packets:238 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:44486 (43.4 KiB)  TX bytes:294 (294.0 b)

ppp1      Link encap:Point-to-Point Protocol
          inet addr:78.93.70.4  P-t-P:212.93.193.15  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1442  Metric:1
          RX packets:219 errors:0 dropped:0 overruns:0 frame:0
          TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:24237 (23.6 KiB)  TX bytes:2330 (2.2 KiB)

ppp2      Link encap:Point-to-Point Protocol
          inet addr:87.109.229.209  P-t-P:84.235.124.10  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1442  Metric:1
          RX packets:7 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:294 (294.0 b)  TX bytes:54 (54.0 b)

Here is the result of the route command:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
212.93.193.15   *               255.255.255.255 UH    0      0        0 ppp1
212.93.193.40   *               255.255.255.255 UH    0      0        0 ppp0
84.235.124.10   *               255.255.255.255 UH    0      0        0 ppp2
86.111.198.0    *               255.255.255.240 U     0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth1
169.254.0.0     *               255.255.0.0     U     0      0        0 eth1

Anyone with ideas on how this might work?

+3
2

PHP curl_multi_*() curl_setopt(CURLOPT_INTERFACE, 'ppp0') ..

, ifconfig. , -, , script, .

+2

, curl/wget. , . PHP script . , fopen/file_get_contents http://. Snoopy .

0

Source: https://habr.com/ru/post/1714432/


All Articles