Skip to content

Commit

Permalink
Add check on NULL in getenv, update Build.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-omarov committed Jul 18, 2024
1 parent a8d332c commit 5c65e22
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,27 @@ jobs:

- name: Copy the session_test file
run: docker exec kphp-build-container-${{matrix.os}} bash -c
"su kitten -c 'cp ${{env.session_php_script}} ${{env.kphp_snippets_dir}}/JobWorkers/'"
"cp ${{env.session_php_script}} ${{env.kphp_snippets_dir}}/JobWorkers/"

- name: Compile the session_test project
run: docker exec kphp-build-container-${{matrix.os}} bash -c
"su kitten -c 'cd ${{env.kphp_snippets_dir}}/JobWorkers/ && ${{env.kphp_root_dir}}/objs/bin/kphp2cpp --cxx ${{matrix.compiler}} session_test.php -I .. -M server'"
"cd ${{env.kphp_snippets_dir}}/JobWorkers/ && ${{env.kphp_root_dir}}/objs/bin/kphp2cpp --cxx ${{matrix.compiler}} session_test.php -I .. -M server"

- name: Start the server
run: docker exec kphp-build-container-${{matrix.os}} bash -c
"su kitten -c 'cd ${{env.kphp_snippets_dir}}/JobWorkers/ && ./kphp_out/server -f 2 --http-port 8080 --job-workers-ratio 0.5 --sql-port 5555 &> log.txt &'"
"cd ${{env.kphp_snippets_dir}}/JobWorkers/ && ./kphp_out/server -f 2 --http-port 8080 --job-workers-ratio 0.5 --sql-port 5555 --user kitten &> log.txt &"

- name: Install curl
run: docker exec kphp-build-container-${{matrix.os}} bash -c
"apt update && apt install curl"

- name: Send a request to the server
run: docker exec kphp-build-container-${{matrix.os}} bash -c
"curl 'http://localhost:8080'"

- name: Read lgos
- name: Read logs
run: docker exec kphp-build-container-${{matrix.os}} bash -c
"su kitten -c 'cd ${{env.kphp_snippets_dir}}/JobWorkers/ && tail -f logs.txt'"
"cd ${{env.kphp_snippets_dir}}/JobWorkers/ && cat log.txt"

# - name: Remove docker container
# run: docker rm -f kphp-build-container-${{matrix.os}}
Expand Down
15 changes: 13 additions & 2 deletions docs/session_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ function handleHttpRequest() {
$timeout = 0.5;
$to_write = ["first_message" => "hello"];

// ["save_path" => "/Users/marat/Desktop/sessions/"]
$main_request = new MyRequest([], $to_write, false, false);
$main_job_id = \JobWorkers\JobLauncher::start($main_request, $timeout);

Expand All @@ -126,9 +125,13 @@ function handleHttpRequest() {
$main_request = new MyRequest([], ["second_message" => "world"], $session_id, true);
$main_job_id = \JobWorkers\JobLauncher::start($main_request, $timeout);

$new_request = new MyRequest([], ["third_message" => "buy"], $session_id, false);
$additional_to_main_request = new MyRequest([], ["third_message" => "buy"], $session_id, false);
$additional_to_main_job_id = \JobWorkers\JobLauncher::start($additional_to_main_request, $timeout);

$new_request = new MyRequest([], ["new_message" => "hi"], false, false);
$new_job_id = \JobWorkers\JobLauncher::start($new_request, $timeout);

$additional_to_main_response = wait($additional_to_main_job_id);
$new_response = wait($new_job_id);
$main_response = wait($main_job_id);

Expand All @@ -140,6 +143,14 @@ function handleHttpRequest() {
echo "<br><br>";
}

if ($additional_to_main_response instanceof MyResponse) {
echo "<br>Opened session:<br>";
var_dump($additional_to_main_response->session_status);
var_dump($additional_to_main_response->session_id);
var_dump($additional_to_main_response->session_array);
echo "<br><br>";
}

if ($new_response instanceof MyResponse) {
echo "<br>Opened session:<br>";
var_dump($new_response->session_status);
Expand Down
6 changes: 3 additions & 3 deletions runtime/sessions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ constexpr static auto C_HTTPONLY = "cookie_httponly";
// TO-DO: reconsider it
const auto skeys = vk::to_array<std::pair<const char *, const mixed>>({
{S_READ_CLOSE, false},
{S_DIR, string(getenv("TMPDIR")).append("sessions/")},
{S_DIR, string((getenv("TMPDIR") != NULL) ? getenv("TMPDIR") : "/tmp/").append("sessions/")},
{S_NAME, string("PHPSESSID")},
{S_LIFETIME, 1440},
{S_PROBABILITY, 1},
Expand Down Expand Up @@ -209,7 +209,7 @@ static bool session_open() {
bool is_new = (!f$file_exists(get_sparam(S_PATH).to_string())) ? 1 : 0;

fprintf(stderr, "[%d]\tOpening the session file %s\n", getpid(), get_sparam(S_PATH).to_string().c_str());
set_sparam(S_FD, open_safe(get_sparam(S_PATH).to_string().c_str(), O_RDWR | O_CREAT, 0777));
set_sparam(S_FD, open_safe(get_sparam(S_PATH).to_string().c_str(), O_RDWR | O_CREAT, 0666));

if (get_sparam(S_FD).to_int() < 0) {
php_warning("Failed to open the file %s", get_sparam(S_PATH).to_string().c_str());
Expand Down Expand Up @@ -323,7 +323,7 @@ static bool session_write() {
fprintf(stderr, "[%d]\t(rewinding) Closed the file\n", getpid());

fprintf(stderr, "[%d]\t(rewinding) Opening the file\n", getpid());
set_sparam(S_FD, open_safe(get_sparam(S_PATH).to_string().c_str(), O_RDWR, 0777));
set_sparam(S_FD, open_safe(get_sparam(S_PATH).to_string().c_str(), O_RDWR, 0666));
fprintf(stderr, "[%d]\t(rewinding) Opened the file\n", getpid());
lock.l_type = F_WRLCK;
fprintf(stderr, "[%d]\t(rewinding) Locking the file\n", getpid());
Expand Down

0 comments on commit 5c65e22

Please sign in to comment.