See this sample code and output.
I run it via cmd on windows.
This code works well, but after some days, freezed and stopped output!
You can see last line of this log, there are not any error or signs!
I was confused as to what could be the cause!
do {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.tsetmc.com/Loader.aspx?ParTree=151313&Flow=0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$headers = array();
$headers[] = 'Connection: keep-alive';
$headers[] = 'Cache-Control: max-age=0';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9';
$headers[] = 'Referer: http://www.tsetmc.com/Loader.aspx?ParTree=151915';
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Accept-Language: en-US,en;q=0.9,fa;q=0.8';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch) . PHP_EOL;
}
if (!$result) {
echo 'Error: No Result.' . PHP_EOL;
}
curl_close($ch);
sleep(60);
}while(true);
output:
* Trying 185.117.206.245:80...
* TCP_NODELAY set
* Connected to www.tsetmc.com (185.117.206.245) port 80 (#0)
> GET /Loader.aspx?ParTree=151313&Flow=0 HTTP/1.1
Host: www.tsetmc.com
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://www.tsetmc.com/Loader.aspx?ParTree=151915
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,fa;q=0.8
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Cache-Control: public, no-cache="Set-Cookie"
< Content-Type: text/html; charset=utf-8
< Content-Encoding: gzip
< Expires: Sat, 12 Sep 2020 14:33:49 GMT
< Set-Cookie: ASP.NET_SessionId=wrqiwgu5u115153ia15ohd4a; path=/; HttpOnly; SameSite=Lax
< Date: Sat, 12 Sep 2020 14:33:40 GMT
< Content-Length: 15623
<
* Connection #0 to host www.tsetmc.com left intact
* Trying 185.117.206.245:80...
* TCP_NODELAY set
* After 2499ms connect time, move on!
* connect to 185.117.206.245 port 80 failed: Timed out
* Trying 185.117.204.245:80...
* TCP_NODELAY set
* Connected to www.tsetmc.com (185.117.204.245) port 80 (#0)
> GET /Loader.aspx?ParTree=151313&Flow=0 HTTP/1.1
Host: www.tsetmc.com
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://www.tsetmc.com/Loader.aspx?ParTree=151915
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,fa;q=0.8
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Cache-Control: public, no-cache="Set-Cookie"
< Content-Type: text/html; charset=utf-8
< Content-Encoding: gzip
< Expires: Sat, 12 Sep 2020 14:34:59 GMT
< Server: Microsoft-IIS/10.0
< Set-Cookie: ASP.NET_SessionId=f5qzrtaopkuhn0q3yjy5h3vx; path=/; HttpOnly; SameSite=Lax
< X-Powered-By: ASP.NET
< Date: Sat, 12 Sep 2020 14:34:51 GMT
< Content-Length: 15623
<
C:\>php -v
PHP 7.2.31 (cli) (built: May 12 2020 10:26:30) ( NTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.31, Copyright (c) 1999-2018, by Zend Technologies
EDIT:
I tried this solution: https://stackoverflow.com/a/64512531
And the result is:
:
:
:
2020-11-03 - 5:29:24
* Trying 185.117.204.245:80...
* TCP_NODELAY set
* Connected to www.tsetmc.com (185.117.204.245) port 80 (#0)
> GET /Loader.aspx?ParTree=151313&Flow=0 HTTP/1.1
Host: www.tsetmc.com
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://www.tsetmc.com/Loader.aspx?ParTree=151915
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,fa;q=0.8
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Cache-Control: public, no-cache="Set-Cookie"
< Content-Type: text/html; charset=utf-8
< Content-Encoding: gzip
< Expires: Tue, 03 Nov 2020 02:03:15 GMT
< Server: Microsoft-IIS/10.0
< Set-Cookie: ASP.NET_SessionId=34cwudfw41fkvibcksu45lnt; domain=.tsetmc.com; path=/; HttpOnly; SameSite=Lax
< Date: Tue, 03 Nov 2020 02:03:06 GMT
< Content-Length: 16989
<
* Connection #0 to host www.tsetmc.com left intact
Done. (121808 B)
Pinging WIN-G2AELSC5ER9 [::1] with 32 bytes of data:
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Ping statistics for ::1:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
2020-11-03 - 5:29:33
* Trying 185.117.204.245:80...
* TCP_NODELAY set
* Connected to www.tsetmc.com (185.117.204.245) port 80 (#0)
> GET /Loader.aspx?ParTree=151313&Flow=0 HTTP/1.1
Host: www.tsetmc.com
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://www.tsetmc.com/Loader.aspx?ParTree=151915
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,fa;q=0.8
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Cache-Control: public, no-cache="Set-Cookie"
< Content-Type: text/html; charset=utf-8
< Content-Encoding: gzip
< Expires: Tue, 03 Nov 2020 01:59:42 GMT
< Set-Cookie: ASP.NET_SessionId=03ymtrwh14eqgxyii1ryijvr; domain=.tsetmc.com; path=/; HttpOnly; SameSite=Lax
< Content-Security-policy: defult-Src 'self'
< X-Content-Type-Options: nosniff
< X-Farams-Options: DENY
< X-XSS-Protection: 1; mode=block
< Date: Tue, 03 Nov 2020 01:59:33 GMT
< Content-Length: 16989
<
* Connection #0 to host www.tsetmc.com left intact
Done. (121808 B)
Pinging WIN-G2AELSC5ER9 [::1] with 32 bytes of data:
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Ping statistics for ::1:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
2020-11-03 - 5:29:43
* Trying 185.117.204.245:80...
* TCP_NODELAY set
* Connected to www.tsetmc.com (185.117.204.245) port 80 (#0)
> GET /Loader.aspx?ParTree=151313&Flow=0 HTTP/1.1
Host: www.tsetmc.com
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://www.tsetmc.com/Loader.aspx?ParTree=151915
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,fa;q=0.8
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Cache-Control: public, no-cache="Set-Cookie"
< Content-Type: text/html; charset=utf-8
< Content-Encoding: gzip
< Expires: Tue, 03 Nov 2020 02:03:50 GMT
< Server: Microsoft-IIS/10.0
< Set-Cookie: ASP.NET_SessionId=wzwab2sgb1ib5afibur0tayf; domain=.tsetmc.com; path=/; HttpOnly; SameSite=Lax
< Date: Tue, 03 Nov 2020 02:03:42 GMT
< Content-Length: 16989
<
No clue. Seems to be a endless loop with 1 min interval over days am I right?
PHP may need more sleep. Sorry for that joke.
You have written, that you execute your php via cmd. I understand that as you could use a batch file.
So I've got an idea for a possible suggestion / solution / workaround for you:
Remove the loop from php and make the loop inside a batch file
batchfile.bat
#ECHO OFF
:loop
echo %date:~0% - %time:~0,8%
REM !YOUR PHP CALL HERE!
#ping -n 60 localhost > nul
cls
GOTO loop
I think you're familiar with php but here the modified code (just remove while and sleep):
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.tsetmc.com/Loader.aspx?ParTree=151313&Flow=0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$headers = array();
$headers[] = 'Connection: keep-alive';
$headers[] = 'Cache-Control: max-age=0';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9';
$headers[] = 'Referer: http://www.tsetmc.com/Loader.aspx?ParTree=151915';
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Accept-Language: en-US,en;q=0.9,fa;q=0.8';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch) . PHP_EOL;
}
if (!$result) {
echo 'Error: No Result.' . PHP_EOL;
}
curl_close($ch);
Edit: It's a long long time ago since I use php/curl last time. I can't remember exactly but I thought there was something with curl and sleep. Idk what. Response of request or something like that. From where do you get the output of your curl loop if I may ask? Anyhow I hope my idea is suitable.
If you like to give it a try don't forget to remove "REM".
I just started programming but I don't know how to get this POST response into a PHP file,
Request URL: http://localhost/getEmployees.php
Request Method: POST
Status Code: 200 OK
Remote Address: 127.0.0.1:63342
Referrer Policy: no-referrer-when-downgrade
access-control-allow-credentials: true
access-control-allow-origin: http://localhost:63342
content-length: 4850
Content-type: text/html; charset=UTF-8
server: PhpStorm 2020.1
vary: origin
X-Powered-By: PHP/7.3.6
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,es-US;q=0.8,es;q=0.7,sm;q=0.6
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 105
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: Phpstorm-7e92279c=4f7ff7c6-1a41-4c9e-90dd-dcc6680dcb42; loginAuthorised=loginAuthorised; companyId=1; userId=10; userName=Claudia+Najera; PHPSESSID=nequ49622cdstv6oh0ahsmis10
Host: localhost:63342
Origin: http://localhost:63342
Pragma: no-cache
Referer: http://localhost:63342/htdocs/flavorite.io/tools/tests.php?_ijt=buaa7pmm8icavombffnis1htfu
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Mobile Safari/537.36
X-Requested-With: XMLHttpRequest
query[generalSearch]: Mario
selectedAllRows: false
requestIds: true
sort[field]:
sort[sort]: asc
What I am trying to do is get query[generalSearch] string. I have in another PHP file to fet the results:
$dbConnection = connection();
$generalSearchJSON = #$_POST['generalSearch'];
$generalSearch = json_decode($generalSearchJSON);
I want to use the $generalSearch variable to search the database. But it doesn't seem to get the result. Any suggestions?
You have a typo.Remove the # from $_POST['generalSearch'];
So you'll get this:
$dbConnection = connection();
$generalSearchJSON = $_POST['generalSearch'];
$generalSearch = json_decode($generalSearchJSON);
<script>
$.post("api.php", {action: 'check_login'}, function (response) {
if (response.status == 'success') {
$('#loginForm').hide();
$('#loginHeader').text('You are already logged in.');
setTimeout(function () {
alert('You will now be redirected.');
$(window.location).attr("href", "http://example.com");
}, 3000);
}
}, "JSON");
</script>
The above jQuery script POSTs this request to a php script in the same folder:
POST http://localhost:63342/100D100/api.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
Referer: http://localhost:63342/100D100/login.html?_ijt=taksdipisi3m6dq085nom202e2
Accept-Language: it-IT
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 18
Host: localhost:63342
Connection: Keep-Alive
Pragma: no-cache
Cookie: Phpstorm-b9495478=581c317c-7b73-4419-92d8-ab238525aac4
action=check_login
It works on a normal server, but fails with a 404 when using PhpStorm's integrated server:
HTTP/1.1 404 Not Found
content-type: text/html
content-length: 148
server: PhpStorm 2016.3.2
date: Tue, 10 Jan 2017 14:19:21 GMT
X-Frame-Options: SameOrigin
X-Content-Type-Options: nosniff
x-xss-protection: 1; mode=block
<!doctype html><title>404 Not Found</title><h1 style="text-align: center">404 Not Found</h1><hr/><p style="text-align: center">PhpStorm 2016.3.2</p>
The file is definitely there. What can I try to resolve this issue?
I have been trying to get data from this web page. I found that I need to pass the camera id to this url using GET method to get image.
But every time I do a curl request I got http_code 500: internal server error
This is my code (I'm still trying out with static camera id):
$curl = curl_init('http://www.mytransport.sg/content/mytransport/home/myconcierge/trafficcameras/jcr:content/par/cameras_slideshow.singleresult.html?cameraid=4701');
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.28 Safari/537.36");
curl_setopt($curl, CURLOPT_REFERER, "http://www.mytransport.sg/content/mytransport/home/myconcierge/trafficcameras.html");
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,true);
$resp = curl_exec($curl);
echo $resp;
$header = curl_getinfo($curl);
echo "<pre>";
print_r($header);
echo "</pre>";
curl_close($curl);
Result I get:
HTTP/1.1 500 Internal Server Error
Date: Mon, 09 Sep 2013 15:26:56 GMT
Server: Microsoft-IIS/5.0
Last-Modified: Thu, 04 Oct 2012 15:55:23 GMT
ETag: "7d2c5-402e-4cb3dc86ef0c0"
Accept-Ranges: bytes
Content-Length: 16430
Vary: Accept-Encoding
Cache-Control: must-revalidate, proxy-revalidate, private, must-revaildate, proxy-revalidate, private Connection: close
Content-Type: text/html
i have next problem
$("#btnsave").click(function () {
$.post('svld.php', {
'fnd': $('#fnd').attr("value")
}, function (data) {
alert(data);
}, 'json');
}
slvd.php
header('Content-type: application/json');
var_dump(json_encode($_POST));
in request i see next
fnd http://ya.ru
and have great response
string(24) "{"fnd":"http:\/\/ya.ru"}"
but alert(data) not runed
if i do same request on file parse.php in same folder
if($_POST['fnd']){
header('Content-type: application/json');
echo json_encode($cntTags->returnArrayTags());
}
all work perfect
Have idea what it can be ?
header list
Date Thu, 08 Jul 2010 12:16:02 GMT
Server Apache/2.2.14 (Win32) PHP/5.3.0
X-Powered-By PHP/5.3.0
Content-Length 38
Keep-Alive timeout=5, max=99
Connection Keep-Alive
Content-Type application/json
Host localhost
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept application/json, text/javascript, */*
Accept-Language ru,en-us;q=0.7,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset windows-1251,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Content-Type application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With XMLHttpRequest
Referer http://localhost/tz/
Content-Length 22
Cookie spylog_test=1
The issue is that your HTTP request is returning this string:
string(24) "{"fnd":"http:\/\/ya.ru"}"
What happens is that jQuery is trying to parse that but it fails because it's not a valid JSON string.
Try using echo instead of var_dump:
echo json_encode($_POST);
var_dump() outputs other information that you don't need, and that will screw up jQuery's JSON parsing.
Content-Type application/json Заголовки запросапоказать исходный код
looks alien to me. Looks like a character-set failure.
try
header('Content-type: application/json; charset=UTF-8');